cordon节点,drain驱逐节点,delete 节点( 二 )

查看pod , 可以看到deploy生成5个pod(nginx-6cf858f6cf-XXXXXXX) , 还有一个pod1 。
[root@k8scloude1 deploy]# kubectl get pods -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESnginx-6cf858f6cf-fwhmh1/1Running052s10.244.251.217k8scloude3<none><none>nginx-6cf858f6cf-hr6bn1/1Running052s10.244.251.218k8scloude3<none><none>nginx-6cf858f6cf-j2ccs1/1Running052s10.244.112.161k8scloude2<none><none>nginx-6cf858f6cf-l7n4w1/1Running052s10.244.112.162k8scloude2<none><none>nginx-6cf858f6cf-t6qxq1/1Running052s10.244.112.163k8scloude2<none><none>pod11/1Running060s10.244.251.216k8scloude3<none><none>假设某天要对k8scloude2进行维护测试 , 不希望k8scloude2节点上被分配新的pod , 可以对某个节点执行cordon之后 , 此节点就不会再调度新的pod了
cordon k8scloude2节点 , k8scloude2节点变为SchedulingDisabled状态
[root@k8scloude1 deploy]# kubectl cordon k8scloude2node/k8scloude2 cordoned[root@k8scloude1 deploy]# kubectl get nodesNAMESTATUSROLESAGEVERSIONk8scloude1Readycontrol-plane,master8dv1.21.0k8scloude2Ready,SchedulingDisabled<none>7d23hv1.21.0k8scloude3Ready<none>7d23hv1.21.0kubectl scale deploy命令使nginx deploy的副本数扩展为10个
[root@k8scloude1 deploy]# kubectl scale deploy nginx --replicas=10deployment.apps/nginx scaled查看pod , 可以发现新生成的pod都被调度到到k8scloude3上 , 某个节点被cordon之后 , 新的pod将不被调度到该节点 , 原先的pod不变 。
[root@k8scloude1 deploy]# kubectl get pod -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESnginx-6cf858f6cf-7fdnr1/1Running04s10.244.251.221k8scloude3<none><none>nginx-6cf858f6cf-fwhmh1/1Running09m9s10.244.251.217k8scloude3<none><none>nginx-6cf858f6cf-g92ls1/1Running04s10.244.251.219k8scloude3<none><none>nginx-6cf858f6cf-hr6bn1/1Running09m9s10.244.251.218k8scloude3<none><none>nginx-6cf858f6cf-j2ccs1/1Running09m9s10.244.112.161k8scloude2<none><none>nginx-6cf858f6cf-l7n4w1/1Running09m9s10.244.112.162k8scloude2<none><none>nginx-6cf858f6cf-lsvsg1/1Running04s10.244.251.223k8scloude3<none><none>nginx-6cf858f6cf-mpwjl1/1Running04s10.244.251.222k8scloude3<none><none>nginx-6cf858f6cf-s8x6b1/1Running04s10.244.251.220k8scloude3<none><none>nginx-6cf858f6cf-t6qxq1/1Running09m9s10.244.112.163k8scloude2<none><none>pod11/1Running09m17s10.244.251.216k8scloude3<none><none>来个极端的例子 , 先把deploy的副本数变为0 , 再变为10 , 此时所有的pod都运行在k8scloude3节点了 。
[root@k8scloude1 deploy]# kubectl scale deploy nginx --replicas=0deployment.apps/nginx scaled[root@k8scloude1 deploy]# kubectl get pod -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod11/1Running010m10.244.251.216k8scloude3<none><none>[root@k8scloude1 deploy]# kubectl scale deploy nginx --replicas=10deployment.apps/nginx scaled[root@k8scloude1 deploy]# kubectl get pod -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESnginx-6cf858f6cf-5cx9s1/1Running08s10.244.251.231k8scloude3<none><none>nginx-6cf858f6cf-6cblj1/1Running08s10.244.251.228k8scloude3<none><none>nginx-6cf858f6cf-827cz1/1Running08s10.244.251.233k8scloude3<none><none>nginx-6cf858f6cf-b989n1/1Running08s10.244.251.229k8scloude3<none><none>nginx-6cf858f6cf-kwxhn1/1Running08s10.244.251.224k8scloude3<none><none>nginx-6cf858f6cf-ljjxz1/1Running08s10.244.251.225k8scloude3<none><none>nginx-6cf858f6cf-ltrpr1/1Running08s10.244.251.227k8scloude3<none><none>nginx-6cf858f6cf-lwf7g1/1Running08s10.244.251.230k8scloude3<none><none>nginx-6cf858f6cf-xw84l1/1Running08s10.244.251.226k8scloude3<none><none>nginx-6cf858f6cf-zpwhq1/1Running08s10.244.251.232k8scloude3<none><none>pod11/1Running011m10.244.251.216k8scloude3<none><none>

经验总结扩展阅读