应用背景:
使用kubeadm部署的kubernetes集群,其master节点默认拒绝将pod调度运行于其上的,加点官方的术语就是:master默认被赋予了一个或者多个“污点(taints)”,“污点”的作用是让该节点拒绝将pod调度运行于其上。那么存在某些情况,比如想让master也成为工作节点可以调度pod运行怎么办呢?
两种方式:①去掉“污点”(taints)【生产环境不推荐】;②让pod能够容忍(tolerations)该节点上的“污点”。
测试环境:
节点名称 | 节点类型 | 版本号 | 部署方式 |
kube-node-01 | Master | v1.11.2 | kubeadm init |
kube-node-02 | Node | v1.11.2 | kubeadm join |
kube-node-03 | Node | v1.11.2 | kubeadm join |
操作步骤:
1. 当前环境
[root@kube-node-01 ~]# kubectl get pod -o wide
No resources found.
2. 准备一个yaml文件创建pod(2副本)
[root@kube-node- ~]# kubectl apply -f test-springboot-rc.yaml
replicationcontroller/test-springboot created
[root@kube-node- ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
test-springboot-6495q / Running 2m 10.244.2.113 kube-node- <none>
test-springboot-b5sq2 / Running 2m 10.244.1.76 kube-node- <none>
以上运行的2个pod分别被调度到节点2和节点3上,目前还不足以说明调度不到节点1上,继续操作;
3. 扩容pod副本观察
[root@kube-node- ~]# kubectl scale rc test-springboot --replicas=3
replicationcontroller/test-springboot scaled
[root@tlsw-pre- ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
test-springboot-6495q / Running 4m 10.244.2.113 kube-node- <none>
test-springboot-68qtw / Running 9s 10.244.2.114 kube-node- <none>
test-springboot-b5sq2 / Running 4m 10.244.1.76 kube-node- <none>
一般情况下,kubernetes的pod调度策略会尽量的安排相同的pod安排至不同的节点,上面推测因为节点1含有污点,pod不得不再次调度到节点2或者节点3上去。
再次测试默认调度,添加pod副本至5个:
[root@tlsw-pre- home]# kubectl scale rc test-springboot --replicas=5
replicationcontroller/test-springboot scaled
[root@tlsw-pre- home]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
test-springboot-4875k / Running 1m 10.244.1.77 kube-node- <none>
test-springboot-6495q / Running 14m 10.244.2.113 kube-node- <none>
test-springboot-68qtw / Running 10m 10.244.2.114 kube-node- <none>
test-springboot-b5sq2 / Running 14m 10.244.1.76 kube-node- <none>
test-springboot-hghwb / Running 1m 10.244.2.115 kube-node- <none>
以上显而易见,master节点(kube-node-01)上一直没有pod运行,因为含有“污点”作祟。
4. 查看master节点的容忍参数
[root@kube-node- ~]# kubectl describe node kube-node-01
……
Taints: node-role.kubernetes.io/master:NoSchedule
Unschedulable: false
……
5.添加污点容忍(并再次增加副本数至6)
根据容忍参数在pod对应的yaml文件中添加“容忍”段,如下:
……
replicas: 6 // 在当前的运行环境副本数(5个)上增加1个副本,用来观察pod调度
……
spec:
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
containers:
- name: test-springboot
……
[root@tlsw-pre- home]# kubectl apply -f test-springboot-rc.yaml
replicationcontroller/test-springboot configured
[root@tlsw-pre- home]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
test-springboot-4875k / Running 10m 10.244.1.77 kube-node-
test-springboot-6495q / Running 23m 10.244.2.113 kube-node-
test-springboot-68qtw / Running 19m 10.244.2.114 kube-node-
test-springboot-6pz2x / ContainerCreating 3s <none> kube-node-01
test-springboot-b5sq2 / Running 23m 10.244.1.76 kube-node-
test-springboot-hghwb / Running 10m 10.244.2.115 kube-node-
很明显,最新的一个pod已经调度至master节点,还在创建中,等待一下即可正常running。
结束.