K8S中的cordon、uncordon和drain

node及pod状态

[root@hanyu-210 ~]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
hanyu-210   Ready    master   31d   v1.16.0
hanyu-211   Ready       31d   v1.16.0
hanyu-212   Ready       31d   v1.16.0
[root@hanyu-210 ~]# kubectl get pods -o wide|grep nginx
nginx-deployment-test-557d8b6448-4pb46   1/1     Running     0          67s     10.244.1.62   hanyu-211              
nginx-deployment-test-557d8b6448-52fk9   1/1     Running     0          67s     10.244.0.42   hanyu-210              
nginx-deployment-test-557d8b6448-h675g   1/1     Running     0          67s     10.244.2.40   hanyu-212              

cordon节点hanyu-212,hanyu-212变为不可调度

[root@hanyu-210 ~]# kubectl cordon hanyu-212
node/hanyu-212 cordoned
[root@hanyu-210 ~]# kubectl get nodes
NAME        STATUS                     ROLES    AGE   VERSION
hanyu-210   Ready                      master   31d   v1.16.0
hanyu-211   Ready                         31d   v1.16.0
hanyu-212   Ready,SchedulingDisabled      31d   v1.16.0

将pod副本数扩到10个,可以看到新增的pod分布到hanyu-210和hanyu-211上

[root@hanyu-210 ~]# kubectl scale --replicas=10 deployment nginx-deployment-test
deployment.apps/nginx-deployment-test scaled
[root@hanyu-210 ~]# kubectl get pods -o wide|grep nginx
nginx-deployment-test-557d8b6448-2jx9j   1/1     Running     0          4m32s   10.244.0.45   hanyu-210              
nginx-deployment-test-557d8b6448-4pb46   1/1     Running     0          8m37s   10.244.1.62   hanyu-211              
nginx-deployment-test-557d8b6448-52fk9   1/1     Running     0          8m37s   10.244.0.42   hanyu-210              
nginx-deployment-test-557d8b6448-cjlrp   1/1     Running     0          4m32s   10.244.0.44   hanyu-210              
nginx-deployment-test-557d8b6448-h675g   1/1     Running     0          8m37s   10.244.2.40   hanyu-212              
nginx-deployment-test-557d8b6448-hklq5   1/1     Running     0          5m11s   10.244.1.63   hanyu-211              
nginx-deployment-test-557d8b6448-k9vbj   1/1     Running     0          5m11s   10.244.0.43   hanyu-210              
nginx-deployment-test-557d8b6448-nbzh4   1/1     Running     0          4m32s   10.244.1.66   hanyu-211              
nginx-deployment-test-557d8b6448-qlm9p   1/1     Running     0          4m32s   10.244.1.65   hanyu-211              
nginx-deployment-test-557d8b6448-xrxp9   1/1     Running     0          5m11s   10.244.1.64   hanyu-211              

unrdon节点hanyu-212,hanyu-212变为可调度

[root@hanyu-210 ~]# kubectl uncordon hanyu-212
node/hanyu-212 uncordoned
[root@hanyu-210 ~]# kubectl get nodes
NAME        STATUS   ROLES    AGE   VERSION
hanyu-210   Ready    master   31d   v1.16.0
hanyu-211   Ready       31d   v1.16.0
hanyu-212   Ready       31d   v1.16.0

再次副本数扩到15,可以看到新增的pod分布到hanyu-210、hanyu-211和hanyu-212上

[root@hanyu-210 ~]# kubectl scale --replicas=15 deployment nginx-deployment-test
deployment.apps/nginx-deployment-test scaled
[root@hanyu-210 ~]# kubectl get pods -o wide|grep nginx
nginx-deployment-test-557d8b6448-2jx9j   1/1     Running     0          7m39s   10.244.0.45   hanyu-210              
nginx-deployment-test-557d8b6448-4jfqv   1/1     Running     0          2m9s    10.244.1.67   hanyu-211              
nginx-deployment-test-557d8b6448-4pb46   1/1     Running     0          11m     10.244.1.62   hanyu-211              
nginx-deployment-test-557d8b6448-52fk9   1/1     Running     0          11m     10.244.0.42   hanyu-210              
nginx-deployment-test-557d8b6448-bmgl5   1/1     Running     0          2m9s    10.244.2.42   hanyu-212              
nginx-deployment-test-557d8b6448-cjlrp   1/1     Running     0          7m39s   10.244.0.44   hanyu-210              
nginx-deployment-test-557d8b6448-ggd8d   1/1     Running     0          2m9s    10.244.2.43   hanyu-212              
nginx-deployment-test-557d8b6448-h675g   1/1     Running     0          11m     10.244.2.40   hanyu-212              
nginx-deployment-test-557d8b6448-hklq5   1/1     Running     0          8m18s   10.244.1.63   hanyu-211              
nginx-deployment-test-557d8b6448-k9vbj   1/1     Running     0          8m18s   10.244.0.43   hanyu-210              
nginx-deployment-test-557d8b6448-lhqzz   1/1     Running     0          2m9s    10.244.2.44   hanyu-212              
nginx-deployment-test-557d8b6448-nbzh4   1/1     Running     0          7m39s   10.244.1.66   hanyu-211              
nginx-deployment-test-557d8b6448-qlm9p   1/1     Running     0          7m39s   10.244.1.65   hanyu-211              
nginx-deployment-test-557d8b6448-s94d4   1/1     Running     0          2m9s    10.244.2.41   hanyu-212              
nginx-deployment-test-557d8b6448-xrxp9   1/1     Running     0          8m18s   10.244.1.64   hanyu-211              

drain节点hanyu-212,hanyu-212变为不可调度,同时驱逐了原来hanyu-212上的pod

[root@hanyu-210 ~]# kubectl drain hanyu-212
node/hanyu-212 already cordoned
error: unable to drain node "hanyu-212", aborting command...

There are pending nodes to be drained:
 hanyu-212
cannot delete Pods with local storage (use --delete-local-data to override): default/nginx-deployment-test-557d8b6448-bmgl5, default/nginx-deployment-test-557d8b6448-ggd8d, default/nginx-deployment-test-557d8b6448-h675g, default/nginx-deployment-test-557d8b6448-lhqzz, default/nginx-deployment-test-557d8b6448-s94d4
cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore): kube-system/kube-flannel-ds-amd64-djgjx, kube-system/kube-proxy-qj5wn
[root@hanyu-210 ~]# kubectl drain hanyu-212 --delete-local-data --ignore-daemonsets
node/hanyu-212 already cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/kube-flannel-ds-amd64-djgjx, kube-system/kube-proxy-qj5wn
evicting pod "zookeeper-2"
evicting pod "mariadb-slave-0"
evicting pod "nginx-deployment-test-557d8b6448-bmgl5"
evicting pod "nginx-deployment-test-557d8b6448-h675g"
evicting pod "nginx-deployment-test-557d8b6448-lhqzz"
evicting pod "nginx-deployment-test-557d8b6448-s94d4"
evicting pod "nginx-deployment-test-557d8b6448-ggd8d"
pod/nginx-deployment-test-557d8b6448-bmgl5 evicted
pod/nginx-deployment-test-557d8b6448-s94d4 evicted
pod/nginx-deployment-test-557d8b6448-h675g evicted
pod/nginx-deployment-test-557d8b6448-ggd8d evicted
pod/zookeeper-2 evicted
pod/nginx-deployment-test-557d8b6448-lhqzz evicted
pod/mariadb-slave-0 evicted
node/hanyu-212 evicted
[root@hanyu-210 ~]# kubectl get node
NAME        STATUS                     ROLES    AGE   VERSION
hanyu-210   Ready                      master   31d   v1.16.0
hanyu-211   Ready                         31d   v1.16.0
hanyu-212   Ready,SchedulingDisabled      31d   v1.16.0
[root@hanyu-210 ~]# kubectl get pods -o wide|grep nginx
nginx-deployment-test-557d8b6448-2jx9j   1/1     Running             0          11m     10.244.0.45   hanyu-210              
nginx-deployment-test-557d8b6448-4jfqv   1/1     Running             0          5m45s   10.244.1.67   hanyu-211              
nginx-deployment-test-557d8b6448-4pb46   1/1     Running             0          15m     10.244.1.62   hanyu-211              
nginx-deployment-test-557d8b6448-52fk9   1/1     Running             0          15m     10.244.0.42   hanyu-210              
nginx-deployment-test-557d8b6448-5ftf8   0/1     ContainerCreating   0          24s             hanyu-210              
nginx-deployment-test-557d8b6448-7chpj   0/1     ContainerCreating   0          24s             hanyu-210              
nginx-deployment-test-557d8b6448-cjlrp   1/1     Running             0          11m     10.244.0.44   hanyu-210              
nginx-deployment-test-557d8b6448-cw2bv   1/1     Running             0          24s     10.244.1.68   hanyu-211              
nginx-deployment-test-557d8b6448-hklq5   1/1     Running             0          11m     10.244.1.63   hanyu-211              
nginx-deployment-test-557d8b6448-k9vbj   1/1     Running             0          11m     10.244.0.43   hanyu-210              
nginx-deployment-test-557d8b6448-nbzh4   1/1     Running             0          11m     10.244.1.66   hanyu-211              
nginx-deployment-test-557d8b6448-qlm9p   1/1     Running             0          11m     10.244.1.65   hanyu-211              
nginx-deployment-test-557d8b6448-tb2p8   0/1     ContainerCreating   0          24s             hanyu-211              
nginx-deployment-test-557d8b6448-xrxp9   1/1     Running             0          11m     10.244.1.64   hanyu-211              
nginx-deployment-test-557d8b6448-zlgsr   0/1     ContainerCreating   0          24s             hanyu-211              

你可能感兴趣的:(K8S中的cordon、uncordon和drain)