一、查看节点上的pod
root@master:/usr/local/bin# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES busybox-master-cf9989dc9-bbsdr 1/1 Running 0 28h 10.244.2.6 node1 <none> <none> busybox-master-cf9989dc9-v98bp 1/1 Running 0 25h 10.244.2.10 node1 <none> <none> busybox-master-cf9989dc9-wczpm 1/1 Running 0 28h 10.244.2.7 node1 <none> <none> nginx-master-fbc95f85-g27fm 1/1 Running 0 9h 10.244.2.21 node1 <none> <none> nginx-master-fbc95f85-qg42w 1/1 Running 0 9h 10.244.2.19 node1 <none> <none> nginx-master-fbc95f85-qpxqn 1/1 Running 0 9h 10.244.2.20 node1 <none> <none> ssh-server-66d95b8bd4-zp69j 1/1 Running 0 25h 10.244.2.9 node1 <none> <none>
二、标记节点不可用
root@master:/usr/local/bin# kubectl cordon node1
node/node1 cordoned
三、查看节点状态
root@master:/usr/local/bin# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready master 6d23h v1.19.13
node Ready <none> 6d10h v1.19.13
node1 Ready,SchedulingDisabled <none> 2d8h v1.19.13
四、查看pod状态
root@master:/usr/local/bin# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-master-fbc95f85-g27fm 1/1 Running 0 9h 10.244.2.21 node1 <none> <none> nginx-master-fbc95f85-qg42w 1/1 Running 0 9h 10.244.2.19 node1 <none> <none> nginx-master-fbc95f85-qpxqn 1/1 Running 0 9h 10.244.2.20 node1 <none> <none>
五、驱赶pod
root@master:/usr/local/bin# kubectl drain node1 --delete-local-data --ignore-daemonsets --force
node/node1 already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/kube-flannel-ds-kvc6x, kube-system/kube-proxy-8znjq, venus-defender/defender-8knnd
evicting pod kube-system/coredns-f9fd979d6-bb5hf
evicting pod default/nginx-master-fbc95f85-qg42w
evicting pod default/ssh-server-66d95b8bd4-zp69j
evicting pod default/busybox-master-cf9989dc9-bbsdr
evicting pod default/nginx-master-fbc95f85-qpxqn
evicting pod default/busybox-master-cf9989dc9-wczpm
evicting pod default/busybox-master-cf9989dc9-v98bp
evicting pod default/nginx-master-fbc95f85-g27fm
pod/coredns-f9fd979d6-bb5hf evicted
pod/nginx-master-fbc95f85-g27fm evicted
pod/nginx-master-fbc95f85-qpxqn evicted
I0819 19:32:46.073806 932974 request.go:645] Throttling request took 1.149915211s, request: GET:https://192.168.33.15:6443/api/v1/namespaces/default/pods/busybox-master-cf9989dc9-v98bp
pod/ssh-server-66d95b8bd4-zp69j evicted
pod/nginx-master-fbc95f85-qg42w evicted
pod/busybox-master-cf9989dc9-wczpm evicted
pod/busybox-master-cf9989dc9-v98bp evicted
pod/busybox-master-cf9989dc9-bbsdr evicted
node/node1 evicted
六、查看pod状态
root@master:~# kubectl get pod -o wide nginx-master-fbc95f85-kqdnv 1/1 Running 0 4m8s 10.244.1.153 node <none> <none> nginx-master-fbc95f85-nnzhp 1/1 Running 0 4m8s 10.244.1.149 node <none> <none> nginx-master-fbc95f85-vvwgn 1/1 Running 0 4m8s 10.244.1.150 node <none> <none>
七、取消标记
root@master:/k8s/pod# kubectl uncordon node1
node/node1 uncordoned
八、查看节点状态
root@master:/k8s/pod# kubectl get node NAME STATUS ROLES AGE VERSION master Ready master 6d23h v1.19.13 node Ready <none> 6d10h v1.19.13 node1 Ready <none> 2d8h v1.19.13