{{ v.name }}
{{ v.cls }}類
{{ v.price }} ¥{{ v.price }}
?
安裝前需要選擇兼容你Kubernetes的版本,不能會(huì)失敗。
ingress由兩部分組成:
以下就是具體的安裝步驟:
Ingress Controller 是負(fù)責(zé)處理 Ingress 請(qǐng)求的組件。Kubernetes 提供了多種 Ingress Controller,您可以根據(jù)需要選擇。以下是常用的 Ingress Controller:
在本教程中,我們將使用 Nginx Ingress Controller 進(jìn)行演示。
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml
一定要把版本后面帶的@摘要值刪除掉。
要?jiǎng)?chuàng)建 Ingress 資源對(duì)象,您可以使用 kubectl 命令:
kubectl apply -f deploy.yaml
#安裝后查看安裝結(jié)果
kubectl get pods -n ingress-nginx
看到下圖的結(jié)果就代表成功了,只要controller是Running,其它是Completed就可以了。
如果發(fā)現(xiàn)安裝失敗,可以嘗試刪除pod再重新kubectl apply -f deploy.yaml。
#強(qiáng)制刪除pod
kubectl delete pod --all -n ingress-nginx --force --grace-period=0
kubectl apply -f deploy.yaml
如果想查看具體的失敗原因,可以使用下面的命令。
kubectl get pods -n ingress-nginx
kubectl describe pod ingress-nginx-controller-6c978d4999-vqfwp --namespace ingress-nginx
vim nginx-deploy.yaml:
apiVersion: apps/v1
kind: Deployment metadata: labels: app: nginx-demo
name: nginx-demo
spec: replicas: 2 selector: matchLabels: app: nginx
template: metadata: labels: app: nginx
spec: containers: - image: nginx
name: nginx --- apiVersion: v1
kind: Service metadata: labels: app: nginx
name: nginx
spec: selector: app: nginx
ports: - port: 8000 protocol: TCP
targetPort: 80
kubecl apply -f nginx-deploy.yaml
kubectl get pod,svc
vim ingress-nginx.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx
spec:
ingressClassName: nginx
rules:
- host: "demo.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: nginx
port:
number: 8000
沒(méi)有域名可以自己在/etc/hosts 增加demo.com:
kubecl apply -f ingress-nginx.yaml
kubectl get ing
查看端口:
kubectl get pods,svc -n ingress-nginx
一般安裝都會(huì)失敗,主要是國(guó)內(nèi)無(wú)法下載鏡像。可以看到第一個(gè)deploy.yaml中要下載兩個(gè)鏡像文件分別是:
有幾種解決方案:
docker tag old_image_name new_image_name