在 kubernetes 1.8 上部署 ingress

准备

本文所需代码在这里

先查看集群状态

1
2
3
4
5
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 15d v1.8.4
k8s-node-1 Ready <none> 15d v1.8.4
k8s-node-2 Ready <none> 15d v1.8.4

ingress 有多种方式

  • deployment 自由调度
  • daemonset 全局调度

官方部署现在是 deployment 方式。在 deployment 自由调度过程中,由于我们需要约束 controller 调度到指定的 node 中,所以需要对 node 进行 label 标签。

1
2
3
4
5
6
7
8
9
10
$ kubectl label nodes k8s-node-1 ingress=proxy
node "k8s-node-1" labeled
$ kubectl label nodes k8s-node-2 ingress=proxy
node "k8s-node-2” labeled

$ kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready master 15d v1.8.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-master,node-role.kubernetes.io/master=
k8s-node-1 Ready <none> 15d v1.8.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,ingress=proxy,kubernetes.io/hostname=k8s-node-1
k8s-node-2 Ready <none> 15d v1.8.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,ingress=proxy,kubernetes.io/hostname=k8s-node-2

安装

1
2
3
4
5
6
7
8
9
10
11
12
$ kubectl apply -f namespace.yaml 
$ kubectl apply -f default-backend.yaml
$ kubectl apply -f configmap.yaml
$ kubectl apply -f tcp-services-configmap.yaml
$ kubectl apply -f udp-services-configmap.yaml
$ kubectl apply -f rbac.yaml
$ kubectl apply -f with-rbac.yaml

$ kubectl get pods --all-namespaces -l app=ingress-nginx -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
ingress-nginx nginx-ingress-controller-64f7567b77-dv7cn 1/1 Running 0 6h 172.31.21.148 k8s-node-2
ingress-nginx nginx-ingress-controller-64f7567b77-zcvkt 1/1 Running 0 6h 172.31.21.147 k8s-node-1

使用

jenkins

1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: jenkins-ui
spec:
rules:
- host: jenkins.idealsoftone.com
http:
paths:
- path: /
backend:
serviceName: jenkins-ui
servicePort: 8080

harbor

1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: harbor-ui
spec:
rules:
- host: hub.idealsoftone.com
http:
paths:
- path: /
backend:
serviceName: harbor-ui
servicePort: 80