前言
环境:k8s 1.22.15、docker
一直对cordon、drain、 taint命令混淆,所以来区别一下。
cordon设置节点不可调度
kubectl cordon NODE命令设置节点不可调度,仅仅是节点不可调度而已,已存在的pod不会驱逐,新的pod不会被调度到该节点上。
Usage:
kubectl cordon NODE [options]
演示示例:
#设置node2不可调度
kubectl cordon node2
#查看节点信息,现在node2已经设置不可调度了,所以新创建的pod不会被调度到node2节点,之前就已经存在于node2节点上的pod也不会被驱逐
[root@matser ~]# kubectl describe node node2 | grep Unschedulable
Unschedulable: true
[root@matser ~]# kubectl get node node2
NAME STATUS ROLES AGE VERSION
node2 Ready,SchedulingDisabled node 353d v1.22.15
#我们发现,当设置节点不可调度的时候,k8s会自动打上污点,如下:
Taints: node.kubernetes.io/unschedulable:NoSchedule
Unschedulable: true
#使用path命令也可以设置节点不可调度
kubectl patch node node2 -p '{"spec":{"unschedulable": true}}'
#使用path命令恢复节点可以可调度
kubectl patch node node2 -p '{"spec":{"unschedulable": false}}'
#除了上面的使用cordon、patch命令设置节点不可调度之后之外,还可以直接修改节点资源来实现节点不可调度
#默认没有unschedulable参数,在spec下添加unschedulable: true 即可实现设置node不可调度
kubectl edit node node2

本文围绕Kubernetes展开,作者因对cordon、drain、taint命令混淆,故而进行区分。介绍了cordon设置节点不可调度,uncordon恢复可调度,drain用于节点停机维护、下线,通过设不可调度并驱逐pod实现,还提及taint可设置更新节点污点。
5162

被折叠的 条评论
为什么被折叠?



