关于kubernetes:Kubernetes-的-Taint-和-Toleration污点和容忍

7次阅读

共计 1613 个字符,预计需要花费 5 分钟才能阅读完成。

    • 作者:SRE 运维博客

      博客地址:https://www.cnsre.cn/

      文章地址:https://www.cnsre.cn/posts/211129946481/

      相干话题:https://www.cnsre.cn/kubernetes/

    • Taint 和 Toleration(污点和容忍)

k8s 集群中,节点亲和性 NodeAffinity 是一种 Pod 上定义的属性,可能让 Pod 能够按找咱们的需要调度到指定节点上,而 Taints (污点) 则于 NodeAffinity (节点亲和性) 是相同的,它是一种 Node 上定义的属性,能够让 Pod 不被调度到带污点的节点上,甚至会对带污点节点上已有的 Pod 进行驱赶。对应的 k8s 能够给 Pod 设置 Tolerations(容忍) 让 Pod 可能对有污点的节点设置容忍,将 Pod 调度到该节点。Taints 个别是配合 Tolerations 应用的。

为 node 设置污点和容忍

NoSchedule: 肯定不能被调度
PreferNoSchedule: 尽量不要调度
NoExecute: 不仅不会调度, 还会驱赶 Node 上已有的 Pod

为 node1 设置 taint:

kubectl taint nodes k8s-node1 key1=value1:NoSchedule
kubectl taint nodes k8s-node1 key1=value1:NoExecute
kubectl taint nodes k8s-node1 key2=value2:NoSchedule

查看 node1 上的 taint:

kubectl describe nodes k8s-node1 |grep Taint

删除下面的 taint:

kubectl taint nodes k8s-node1 key1:NoSchedule-
kubectl taint nodes k8s-node1 key1:NoExecute-
kubectl taint nodes k8s-node1 key2:NoSchedule-
kubectl taint nodes k8s-node1 key1-     # 删除指定 key 所有的 effect

为 pod 设置 toleration

只有在 pod 的 spec 中设置 tolerations 字段即可,能够有多个 key,如下所示:

tolerations:            # containers 同级
- key: "key1"           # 能容忍的污点 key
  operator: "Equal"     # Equal 等于示意 key=value,Exists 不等于,示意当值不等于上面 value 失常
  value: "value1"       # 值
  effect: "NoSchedule"  # effect 策略,能够设置为 NoSchedule、PreferNoSchedule 或 NoExecute
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoExecute"
- key: "node.alpha.kubernetes.io/unreachable"
  operator: "Exists"
  effect: "NoExecute"
  tolerationSeconds: 4000
  • tolerationscontainers 同级。
  • key 能容忍的污点 key
  • operator Equal 等于示意 key=valueExists 不等于,示意当值不等于上面 value 失常
  • value 能够设置为 NoSchedulePreferNoScheduleNoExecute
  • effect effect 策略
  • tolerationSeconds 是当 pod 须要被驱赶时,能够持续在 node 上运行的工夫。

具体的应用办法请参考官网文档。

    • 作者:SRE 运维博客

      博客地址:https://www.cnsre.cn/

      文章地址:https://www.cnsre.cn/posts/211129946481/

      相干话题:https://www.cnsre.cn/tags/kubernetes/

正文完
 0