配置默認(rèn)的backend
為了讓Ingress Controller正常啟動(dòng),需要給它配置一個(gè)默認(rèn)的backend,用于當(dāng)客戶端訪問的URL地址不存在時(shí),能夠返回一個(gè)正確的404應(yīng)答。
這個(gè)backend服務(wù)用任何應(yīng)用實(shí)現(xiàn)都可以哑芹,只要滿足默認(rèn)對(duì)/path的訪問返回404的應(yīng)答,同時(shí)能夠提供/healthz路徑以提供kubelet完成對(duì)它的健康檢查捕透。
這里default-backend的定義文件復(fù)制于kubernetes官方文檔聪姿。?
https://github.com/kubernetes/ingress/blob/master/examples/deployment/nginx/default-backend.yaml
所需鏡像地址為:gcr.io/google_containers/defaultbackend:1.0?
這里我已經(jīng)push到了本地倉(cāng)庫(kù)里。?
內(nèi)容如下:
apiVersion: extensions/v1beta1kind:Deploymentmetadata:? name:default-http-backendlabels:? ? k8s-app:default-http-backendnamespace: kube-systemspec:? replicas:1template:? ? metadata:? ? ? labels:? ? ? ? k8s-app:default-http-backendspec:? ? ? terminationGracePeriodSeconds:60containers:? ? ? - name:default-http-backend#Anyimage is permissableaslongas:? ? ? ? #1.Itserves a404page at /? ? ? ? #2.Itserves200on a /healthz endpoint? ? ? ? image:192.168.121.140:5000/defaultbackend? ? ? ? livenessProbe:? ? ? ? ? httpGet:? ? ? ? ? ? path: /healthz? ? ? ? ? ? port:8080scheme:HTTPinitialDelaySeconds:30timeoutSeconds:5ports:? ? ? ? - containerPort:8080resources:? ? ? ? ? limits:? ? ? ? ? ? cpu:10m? ? ? ? ? ? memory:20Mi? ? ? ? ? requests:? ? ? ? ? ? cpu:10m? ? ? ? ? ? memory:20Mi---apiVersion: v1kind:Servicemetadata:? name:default-http-backendnamespace: kube-system? labels:? ? k8s-app:default-http-backendspec:? ports:? - port:80targetPort:8080selector:? ? k8s-app:default-http-backend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
創(chuàng)建backend
# kubectl apply -f default-backend.yaml
1
在kubernetes中乙嘀,Ingress Controller將以Pod的形式運(yùn)行末购,監(jiān)控apiserver的/ingress接口后端的backend services,如果service發(fā)生變化虎谢,則Ingress Controller自動(dòng)更新其轉(zhuǎn)發(fā)規(guī)則盟榴。
在此使用谷歌提供的nginx-ingress-controller鏡像。鏡像地址為:gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.11(yaml中修改為了本地鏡像)
這里是針對(duì)TCP的負(fù)載均衡例子婴噩。
對(duì)kubernetes學(xué)習(xí)記錄(6)——Guestbook Demo?frontend service做負(fù)載均衡擎场。
首先是nginx-tcp-ingress-configmap.yaml
yaml定義文件復(fù)制自https://github.com/kubernetes/ingress/blob/master/examples/tcp/nginx/nginx-tcp-ingress-configmap.yaml?
內(nèi)容如下:(將9000端口轉(zhuǎn)發(fā)到defaulf/frontend:80服務(wù)端口上)
apiVersion: v1kind: ConfigMapmetadata:? name: nginx-tcp-ingress-configmapnamespace: kube-systemdata:9000:"default/frontend:80"
1
2
3
4
5
6
7
創(chuàng)建
# kubectl create -f nginx-tcp-ingress-configmap.yaml
1
nginx-tcp-ingress-controller.yaml定義文件復(fù)制自https://github.com/kubernetes/ingress/blob/master/examples/tcp/nginx/nginx-tcp-ingress-controller.yaml
內(nèi)容如下:
apiVersion: v1kind: ReplicationControllermetadata:? name: nginx-ingress-controllerlabels:? ? k8s-app: nginx-ingress-lbnamespace: kube-systemspec:? replicas:1selector:? ? k8s-app: nginx-tcp-ingress-lbtemplate:? ? metadata:? ? ? labels:? ? ? ? k8s-app: nginx-tcp-ingress-lbname: nginx-tcp-ingress-lbspec:? ? ? terminationGracePeriodSeconds:60containers:-image:192.168.121.140:5000/nginx-ingress-controllername: nginx-tcp-ingress-lbreadinessProbe:? ? ? ? ? httpGet:? ? ? ? ? ? path: /healthz? ? ? ? ? ? port:10254scheme: HTTP? ? ? ? livenessProbe:? ? ? ? ? httpGet:? ? ? ? ? ? path: /healthz? ? ? ? ? ? port:10254scheme: HTTP? ? ? ? ? initialDelaySeconds:10timeoutSeconds:1env:-name: POD_NAME? ? ? ? ? ? valueFrom:? ? ? ? ? ? ? fieldRef:? ? ? ? ? ? ? ? fieldPath: metadata.name-name: POD_NAMESPACE? ? ? ? ? ? valueFrom:? ? ? ? ? ? ? fieldRef:? ? ? ? ? ? ? ? fieldPath: metadata.namespace? ? ? ? ports:-containerPort:80hostPort:80-containerPort:443hostPort:443-containerPort:9000hostPort:9000args:-/nginx-ingress-controller---default-backend-service=$(POD_NAMESPACE)/default-http-backend---tcp-services-configmap=$(POD_NAMESPACE)/nginx-tcp-ingress-configmap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
創(chuàng)建:
# kubectl create -f nginx-tcp-ingress-controller.yaml
1
從上圖看出nginx-ingress-controller-fm45m運(yùn)行在192.168.121.145上。之前的nginx-tcp-ingress-configmap定義的端口號(hào)是9000几莽。
訪問192.168.121.145:9000直接可以訪問到Guestbook迅办。