zoukankan      html  css  js  c++  java
  • kubernetes taint和toleration

    Taint(污点)和 Toleration(容忍)可以作用于 node 和 pod 上,其目的是优化 pod 在集群间的调度,这跟节点亲和性类似,只不过它们作用的方式相反,具有 taint 的 node 和 pod 是互斥关系,而具有节点亲和性关系的 node 和 pod 是相吸的。另外还有可以给 node 节点设置 label,通过给 pod 设置 nodeSelector 将 pod 调度到具有匹配标签的节点上。

    Taint 和 toleration 相互配合,可以用来避免 pod 被分配到不合适的节点上。每个节点上都可以应用一个或多个 taint ,这表示对于那些不能容忍这些 taint 的 pod,是不会被该节点接受的。如果将 toleration 应用于 pod 上,则表示这些 pod 可以(但不要求)被调度到具有相应 taint 的节点上。

    示例

    以下分别以为 node 设置 taint 和为 pod 设置 toleration 为例。

    为 node 设置 taint

    为 node1 设置 taint:

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

     

    删除上面的 taint:

    kubectl taint nodes node1 key1:NoSchedule-
    kubectl taint nodes node1 key1:NoExecute-
    kubectl taint nodes node1 key2:NoSchedule-

     

    查看 node1 上的 taint:

    kubectl describe nodes node1

     

    为 pod 设置 toleration

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

    tolerations:
    - key: "key1"
      operator: "Equal"
      value: "value1"
      effect: "NoSchedule"
    - key: "key1"
      operator: "Equal"
      value: "value1"
      effect: "NoExecute"
    - key: "node.alpha.kubernetes.io/unreachable"
      operator: "Exists"
      effect: "NoExecute"
      tolerationSeconds: 6000

     

    • value 的值可以为 NoSchedulePreferNoSchedule 或 NoExecute
    • tolerationSeconds 是当 pod 需要被驱逐时,可以继续在 node 上运行的时间。

    详细使用方法请参考官方文档

     

  • 相关阅读:
    Go语言对etcd的基本操作
    etcd命令行基本操作
    etcd集群部署
    第二十一天python3 python的正则表达式re模块学习
    第二十天python3 正则表达式
    jenkins多分支构建选择
    第十九天python3 json和messagepack
    华为交换机设置ntp时间同步
    交换机端口光衰问题排查
    第十八天python3 序列化和反序列化
  • 原文地址:https://www.cnblogs.com/peteremperor/p/12197857.html
Copyright © 2011-2022 走看看