k8s 下线node正确处理姿势
1.获取节点列表
[root@k8s-master1 ~]# kubectl get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-node1 Ready <none> 35d v1.17.5 10.23.215.243 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node2 Ready <none> 35d v1.17.5 10.23.215.244 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node3 Ready <none> 35d v1.17.5 10.23.215.245 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9
2.设置不可调度
[root@k8s-master1 ~]# kubectl cordon k8s-node3 node/k8s-node3 cordoned [root@k8s-master1 ~]# kubectl get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-node1 Ready <none> 35d v1.17.5 10.23.215.243 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node2 Ready <none> 35d v1.17.5 10.23.215.244 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node3 Ready,SchedulingDisabled <none> 35d v1.17.5 10.23.215.245 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9
恢复可调度
[root@k8s-master1 ~]# kubectl uncordon k8s-node3 node/k8s-node3 uncordoned [root@k8s-master1 ~]# kubectl get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-node1 Ready <none> 35d v1.17.5 10.23.215.243 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node2 Ready <none> 35d v1.17.5 10.23.215.244 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node3 Ready <none> 35d v1.17.5 10.23.215.245 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9
3.驱逐节点上的Pod
[root@k8s-master1 ~]# kubectl drain k8s-node3 node/k8s-node3 already cordoned evicting pod "alertmanager-76885994-vgzwb" evicting pod "nginx-deployment-8d9f7c4f-cmbn2" evicting pod "coredns-66cd74bdd6-d8pt5" evicting pod "nfs-client-provisioner-644c45ff78-kqgs8" evicting pod "prometheus-0" pod/nfs-client-provisioner-644c45ff78-kqgs8 evicted pod/nginx-deployment-8d9f7c4f-cmbn2 evicted pod/prometheus-0 evicted pod/alertmanager-76885994-vgzwb evicted pod/coredns-66cd74bdd6-d8pt5 evicted node/k8s-node3 evicted
如遇到daemonsets报错可以增加参数 --ignore-daemonsets
[root@k8s-master1 ~]# kubectl drain k8s-node3 --ignore-daemonsets node/k8s-node3 already cordoned node/k8s-node3 drained
4.删除节点
查看节点上是否还有pod运行
[root@k8s-master1 ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES busybox 0/1 Completed 0 14d 10.244.36.66 k8s-node1 <none> <none> nginx-deployment-8d9f7c4f-dsdvw 1/1 Running 1 8d 10.244.36.76 k8s-node1 <none> <none> nginx-deployment-8d9f7c4f-kqq5p 1/1 Running 2 8d 10.244.169.141 k8s-node2 <none> <none> nginx-deployment-8d9f7c4f-pnfbz 1/1 Running 0 2m25s 10.244.36.79 k8s-node1 <none> <none>
删除节点
[root@k8s-master1 ~]# kubectl delete node k8s-node3 node "k8s-node3" deleted
查看节点是否被删除
[root@k8s-master1 ~]# kubectl get node -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME k8s-node1 Ready <none> 35d v1.17.5 10.23.215.243 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9 k8s-node2 Ready <none> 35d v1.17.5 10.23.215.244 <none> CentOS Linux 7 (Core) 3.10.0-1062.4.1.el7.x86_64 docker://18.9.9