kubernetes Ingress網絡配置說明
阿新 • • 發佈:2018-03-17
ingress kubernetes ingress ingress-controlle docker鏡像地址
默認後端服務鏡像: registry.cn-qingdao.aliyuncs.com/kube8s/defaultbackend:1.0
nginx-Ingress-controller服務鏡像:registry.cn-qingdao.aliyuncs.com/kube8s/nginx-ingress-controller:0.8.3
測試服務鏡像:registry.cn-qingdao.aliyuncs.com/icommon/hello-world:latest
部署Ingress-controlle默認後端服務
1.配置文件
$ cat default-http-backend.yaml apiVersion: v1 kind: ReplicationController metadata: name: default-http-backend namespace: kube-system spec: replicas: 1 selector: k8s-app: default-http-backend template: metadata: labels: k8s-app: default-http-backend spec: terminationGracePeriodSeconds: 60 containers: - name: default-http-backend image: registry.cn-qingdao.aliyuncs.com/kube8s/defaultbackend:1.0 livenessProbe: httpGet: path: /healthz port: 8080 scheme: HTTP initialDelaySeconds: 30 timeoutSeconds: 5 ports: - containerPort: 8080 resources: limits: cpu: 10m memory: 20Mi requests: cpu: 10m memory: 20Mi --- apiVersion: v1 kind: Service metadata: name: default-http-backend labels: k8s-app: default-http-backend namespace: kube-system spec: ports: - port: 80 targetPort: 8080 selector: k8s-app: default-http-backend
2.啟動服務
kubectl create -f default-http-backend.yaml
3.驗證
curl http://$pod_ip:8080/healthz
返回OK,說明部署成功
pod_ip,可以使用kubectl describe 獲取
部署nginx-Ingress-controller服務
1.配置文件
$ cat ingress-controller.yaml apiVersion: v1 kind: ReplicationController metadata: name: nginx-ingress-controller namespace: kube-system labels: k8s-app: nginx-ingress-lb spec: replicas: 1 selector: k8s-app: nginx-ingress-lb template: metadata: labels: k8s-app: nginx-ingress-lb name: nginx-ingress-lb spec: #跟apiserver通信采用的serviceaccount不是默認的default,需要一個token,serviceaccount文件見下面 serviceAccount: admin-user serviceAccountName: admin-user hostNetwork: true #解決端口無法映射問題 terminationGracePeriodSeconds: 60 containers: - image: registry.cn-qingdao.aliyuncs.com/kube8s/nginx-ingress-controller:0.8.3 name: nginx-ingress-lb readinessProbe: httpGet: path: /healthz port: 80 scheme: HTTP livenessProbe: httpGet: path: /healthz port: 80 scheme: HTTP initialDelaySeconds: 10 timeoutSeconds: 1 env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: KUBERNETES_MASTER value: https://192.168.6.110:6443 #kubeapiserver 地址 ports: - containerPort: 80 hostPort: 80 - containerPort: 443 hostPort: 443 args: - /nginx-ingress-controller - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
serviceAccount文件
$ cat admin-user.yaml apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kube-system
2.啟動服務
kubectl create -f admin-user.yaml
kubectl create -f ingress-controller.yaml
3.驗證
curl http://$node_ip:8080/healthz
返回OK,說明部署成功
部署hello-world測試服務
1.配置文件
$cat hello-world.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 3
template:
metadata:
labels:
k8s-app: hello-world
spec:
containers:
- name: hello-world
image: registry.cn-qingdao.aliyuncs.com/icommon/hello-world:latest
---
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 31180
selector:
k8s-app: hello-world
2.啟動服務
kubectl create -f hello-world.yaml
3.驗證服務
curl http://$node_ip:31180/hello-world/index.jsp
返回以下內容,說明成功部署
<html>
<body>
<h1>Hello World?</h1>
<h2>Hello World!</h2>
</body>
</html>
部署Ingress服務
1.配置文件
$ cat ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
spec:
rules:
- http:
paths:
- path: /hello-world/index.jsp
backend:
serviceName: hello-world
servicePort: 8080
2.啟動服務
kubectl create -f ingress.yaml
3.驗證
curl http://$node_ip/hello-world/index.jsp
返回以下內容,說明成功部署
<html>
<body>
<h1>Hello World?</h1>
<h2>Hello World!</h2>
</body>
</html>
kubernetes Ingress網絡配置說明