k8s设置node不可调度

本文介绍了如何使用kubectl工具在Kubernetes集群中管理节点的调度状态,包括通过patch和cordon命令设置及取消节点的不可调度状态,以及使用taint添加和移除污点来控制节点调度。这些操作对于集群资源管理和维护至关重要。
摘要由CSDN通过智能技术生成

主要通过以下几种方法:

一、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>      ####污点已经消失
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值