主要通过以下几种方法:
一、patch方式
[root@node1 ~]# kubectl patch node node1 -p '{"spec":{"unschedulable":true}}'
或者也可以通过编辑yaml文件的方式,如下:
apiVersion: v1
kind: Node
metadata:
name: k8s-master
labels:
kubernetes.io/hostname: node1
spec:
unschedulable: true
取消方式:
[root@node1 ~]# kubectl uncordon node1 ###直接uncordon就可以
node/node1 uncordoned
举例如下:
[root@node1 ~]# kubectl patch node node1 -p '{"spec":{"unschedulable":true}}'
node/node1 patched
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Taints: node.kubernetes.io/unschedulable:NoSchedule
Unschedulable: true ###此值为false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 10m kubelet Node node1 status is now: NodeNotSchedulable
Normal NodeSchedulable 10m kubelet Node node1 status is now: NodeSchedulable
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Taints: node.kubernetes.io/unschedulable:NoSchedule
Unschedulable: true
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeSchedulable 10m kubelet Node node1 status is now: NodeSchedulable
Normal NodeNotSchedulable 4s (x2 over 11m) kubelet Node node1 status is now: NodeNotSchedulable ###节点此时更新为不可调度
取消不可调度:
[root@node1 ~]# kubectl uncordon node1
node/node1 uncordoned
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Unschedulable: false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeSchedulable 12m kubelet Node node1 status is now: NodeSchedulable
Normal NodeNotSchedulable 80s (x2 over 12m) kubelet Node node1 status is now: NodeNotSchedulable
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Unschedulable: false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 85s (x2 over 12m) kubelet Node node1 status is now: NodeNotSchedulable
Normal NodeSchedulable 3s (x2 over 12m) kubelet Node node1 status is now: NodeSchedulable ###节点此时更新为可调度
二、cordon方式
[root@node1 ~]# kubectl cordon node1
取消使用uncordon
[root@node1 ~]# kubectl uncordon node1
举例如下:
[root@node1 ~]# kubectl cordon node1 ###设置不可调度
node/node1 cordoned
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Taints: node.kubernetes.io/unschedulable:NoSchedule
Unschedulable: true ###值为true
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 5s kubelet Node node1 status is now: NodeNotSchedulable ####此时节点不可调度
[root@node1 ~]#
[root@node1 ~]# kubectl uncordon node1 ####取消调度
node/node1 uncordoned
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Unschedulable: false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 13s kubelet Node node1 status is now: NodeNotSchedulable
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Unschedulable: false ####值为false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 24s kubelet Node node1 status is now: NodeNotSchedulable
Normal NodeSchedulable 4s kubelet Node node1 status is now: NodeSchedulable ####此时节点可调度
[root@node1 ~]# kubectl describe node node1 | grep -i schedu
Unschedulable: false
kube-system kube-scheduler-node1 100m (0%) 0 (0%) 0 (0%) 0 (0%) 19d
Normal NodeNotSchedulable 32s kubelet Node node1 status is now: NodeNotSchedulable
Normal NodeSchedulable 12s kubelet Node node1 status is now: NodeSchedulable
[root@node1 ~]#
三、taint污点方式
[root@node1 ~]# kubectl taint nodes node1 key=value:NoSchedule ###除非是设置了容忍toleration
tolerations:
- key: "key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
[root@node1 ~]# kubectl taint nodes node1 key:NoSchedule- ####取消taint
举例如下;
[root@node1 ~]# kubectl taint nodes node1 key=value:NoSchedule
node/node1 tainted
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i taint
Taints: key=value:NoSchedule ###有污点显示不可调度
[root@node1 ~]# kubectl taint nodes node1 key:NoSchedule-
node/node1 untainted
[root@node1 ~]#
[root@node1 ~]# kubectl describe node node1 | grep -i taint
Taints: <none> ####污点已经消失