情景
1master + 1worker的集群,因worker节点没续费,NotReady了。现要将独苗苗master节点打Taint,以将pod调度到master上。
[root@master k8s]# kgn
NAME STATUS ROLES AGE VERSION
master Ready control-plane 48d v1.28.1
node-1 NotReady <none> 47d v1.27.0
nginx-deployment相关pod,因node1状态异常,一直为pending状态。
[root@master k8s]# kgp -o wide
nginx-deployment-f7599d4c-hbns5 0/1 Pending 0 22d <none> <none> <none> <none>
nginx-deployment-f7599d4c-sn5mw 0/1 Pending 0 22d <none> <none> <none> <none>
nginx-deployment-f7599d4c-t4wfc 1/1 Terminating 0 47d 10.244.1.5 node-1 <none> <none>
nginx-deployment-f7599d4c-x8lzp 1/1 Terminating 0 47d 10.244.1.4 node-1 <none> <none>
实现
master配置Taints
Taint的两个常见用法
// 添加Taint
kubectl taint nodes master node-role.kubernetes.io/master:PreferNoSchedule
// 移除Taint
kubectl taint nodes node1 key1=value1:NoSchedule-
查看节点现有Taints
[root@master ~]# kdes node master | grep Taints
Taints: node-role.kubernetes.io/control-plane:NoSchedule
参考污点与容忍度,control-plane:NoSchedule,表示只有拥有和这个污点相匹配的容忍度的 Pod 才能够被分配到这个节点。
移除原有NoSchedule的Taint:
[root@master k8s]# kubectl taint nodes master node-role.kubernetes.io/control-plane:NoSchedule-
node/master untainted
查看原node1上的pod,重新调度过程
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 43m default-scheduler 0/2 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 1 node(s) had untolerated taint {node.kubernetes.io/unreachable: }. preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling..
Warning FailedScheduling 14m (x6 over 41m) default-scheduler 0/2 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 1 node(s) had untolerated taint {node.kubernetes.io/unreachable: }. preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling..
Normal Scheduled 5m19s default-scheduler Successfully assigned default/nginx-deployment-f7599d4c-hbns5 to master
Normal Pulling 5m2s kubelet Pulling image "nginx:1.7.9"
Normal Pulled 4m1s kubelet Successfully pulled image "nginx:1.7.9" in 1m0.958s (1m0.962s including waiting)
Normal Created 4m kubelet Created container nginx
Normal Started 3m59s kubelet Started container nginx
可见,master节点的NoSchedule的Taint被移除,并新增master:PreferNoSchedule的Taint后,原调度到node1的pod,被重新调度到master节点。
[root@master k8s]# kgp -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deployment-f7599d4c-hbns5 1/1 Running 0 22d 10.244.0.8 master <none> <none>
nginx-deployment-f7599d4c-sn5mw 1/1 Running 0 22d 10.244.0.9 master <none> <none>
nginx-deployment-f7599d4c-t4wfc 1/1 Terminating 0 47d 10.244.1.5 node-1 <none> <none>
nginx-deployment-f7599d4c-x8lzp 1/1 Terminating 0 47d 10.244.1.4 node-1 <none> <none>