k8s中污点设置

污点

kubectl taint
Ⅰ、 污点 ( Taint ) 的组成
使用 kubectl taint 命令可以给某个 Node 节点设置污点,Node 被设置上污点之后就和 Pod 之间存在了一种相
斥的关系,可以让 Node 拒绝 Pod 的调度执行,甚至将 Node 已经存在的 Pod 驱逐出去
每个污点的组成如下:
key=value:effect
每个污点有一个 key 和 value 作为污点的标签,其中 value 可以为空,effect 描述污点的作用。当前 taint
effect 支持如下三个选项:
NoSchedule :表示 k8s 将不会将 Pod 调度到具有该污点的 Node 上
PreferNoSchedule :表示 k8s 将尽量避免将 Pod 调度到具有该污点的 Node 上
NoExecute :表示 k8s 将不会将 Pod 调度到具有该污点的 Node 上,同时会将 Node 上已经存在的 Pod 驱
逐出去
Ⅱ、污点的设置、查看和去除
设置污点
kubectl taint nodes node1 key1=value1:NoSchedule
节点说明中,查找 Taints 字段
kubectl describe pod pod-name
去除污点减号
kubectl taint nodes node1 key1:NoSchedule-

apiVersion: v1
kind: Pod
metadata:
name: affinity
labels:
app: node-affinity-pod
spec:
containers:
- name: with-node-affinity
image: hub.atguigu.com/library/myapp:v1
tolerations: #容忍污点
- key: “key1” #污点key
operator: “Equal”
value: “value1”
effect: “NoSchedule”
tolerationSeconds: 3600 #容忍时间

容忍(Tolerations)

设置了污点的 Node 将根据 taint 的 effect:NoSchedule、PreferNoSchedule、NoExecute 和 Pod 之间产生
互斥的关系,Pod 将在一定程度上不会被调度到 Node 上。 但我们可以在 Pod 上设置容忍 ( Toleration ) ,意思
是设置了容忍的 Pod 将可以容忍污点的存在,可以被调度到存在污点的 Node 上
pod.spec.tolerations
tolerations:
- key: “key1”
operator: “Equal”
value: “value1”
effect: “NoSchedule”
tolerationSeconds: 3600
- key: “key1”
operator: “Equal”
value: “value1”
effect: “NoExecute”
- key: “key2”
operator: “Exists”
effect: “NoSchedule”
其中 key, vaule, effect 要与 Node 上设置的 taint 保持一致
operator 的值为 Exists 将会忽略 value 值
tolerationSeconds 用于描述当 Pod 需要被驱逐时可以在 Pod 上继续保留运行的时间 #类似限期驱离

Ⅰ、当不指定 key 值时,表示容忍所有的污点 key:
tolerations:
- operator: “Exists”
Ⅱ、当不指定 effect 值时,表示容忍所有的污点作用
tolerations:
- key: “key”
operator: “Exists”
Ⅲ、有多个 Master 存在时,防止资源浪费,可以如下设置,让master也启动pod
kubectl taint nodes Node-Name node-role.kubernetes.io/master=:PreferNoSchedule

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值