K8S中的cordon、uncordon和drain node标签 节点标签

drain:驱除+不可调度

cordon:不可调度

uncordon:可调度

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
3人点赞
日记本
更多精彩内容,就在简书APP

作者:sjyu_eadd
链接:https://www.jianshu.com/p/752be98e9077
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值