$ kubectl describe node|grep -E "Name:|Taints:"
Name: ops-master-1
Taints: node-role.kubernetes.io/master:NoSchedule
Name: ops-master-2
Taints: node-role.kubernetes.io/master:NoSchedule
Name: ops-master-3
Taints: node-role.kubernetes.io/master:NoSchedule
Name: ops-worker-1
Taints: <none>
Name: ops-worker-2
Taints: <none>
$ kubectl taint nodes --all node-role.kubernetes.io/master-
node/ops-master-1 untainted
node/ops-master-2 untainted
node/ops-master-3 untainted
taint "node-role.kubernetes.io/master" not found
taint "node-role.kubernetes.io/master" not found
# 因为worker节点无node-role.kubernetes.io/master-标签,所以执行上述操作会提示节点不存在。
设置完以后,查看发现有pod已经调度在ops-master-3节点上。
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-node1-5f9555db6b-g4cg7 1/1 Running 0 9m20s 172.25.186.67 ops-master-3 <none> <none>
nginx-node1-5f9555db6b-rq2pn 1/1 Running 0 3h4m 172.25.78.77 ops-worker-1 <none> <none>
nginx-test-6b7c99bbb-8sfh7 1/1 Running 0 175m 172.25.50.140 ops-worker-2 <none> <none>
nginx-test-6b7c99bbb-hp62s 1/1 Running 0 175m 172.25.50.139 ops-worker-2 <none> <none>
# 设置ops-master-1不可调度
$ kubectl taint node ops-master-1 node-role.kubernetes.io/master=:NoSchedule
node/ops-master-1 tainted
# 设置ops-master-3不可调度且已有pod被驱逐
$ kubectl taint node ops-master-3 node-role.kubernetes.io/master=:NoExecute
node/ops-master-3 tainted
$ kubectl describe node|grep -E "Name:|Taints:"
Name: ops-master-1
Taints: node-role.kubernetes.io/master:NoSchedule
Name: ops-master-2
Taints: <none>
Name: ops-master-3
Taints: <none>
Name: ops-worker-1
Taints: <none>
Name: ops-worker-2
Taints: <none>
$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-node1-5f9555db6b-89hrf 0/1 Pending 0 58s <none> <none> <none> <none>
nginx-node1-5f9555db6b-rq2pn 1/1 Running 0 3h10m 172.25.78.77 ops-worker-1 <none> <none>
nginx-test-6b7c99bbb-8sfh7 1/1 Running 0 3h1m 172.25.50.140 ops-worker-2 <none> <none>
nginx-test-6b7c99bbb-hp62s 1/1 Running 0 3h1m 172.25.50.139 ops-worker-2 <none> <none>
?原在ops-master-3节点节点上的pod被驱逐。
一般情况下,master节点均设置不可调度以确保集群高可用性要求。
?