zoukankan      html  css  js  c++  java
  • Kubernetes 的 Taint 和 Toleration(污点和容忍)


    作者: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/


  • 相关阅读:
    SAS学习 day10
    SAS学习 day9
    SAS学习 day8
    Python解释器 发展史
    os. 模块
    字典
    类型1
    计算机编码
    EDA 会议整理
    2020-8-27
  • 原文地址:https://www.cnblogs.com/cnsre/p/15618178.html
Copyright © 2011-2022 走看看