Node 污点与 Pod 容忍度
本章涉及的两个高级调度特性为:
Node 污点:在
nodes.spec.taints
进行相关配置;Pod 容忍度:在
pods.spec.tolerations
进行相关配置;
🦁 只有当一个 Pod 能够容忍某个 Node 中的污点,才能够被调度至该 Node 上。
Node 污点
🍓 一个污点信息的结构是 =:,其中 可以为空。
💫 每个污点都可以关联一个效果,即 ,共有下面三种效果:
NoSchedule:(调度期间生效)如果某个 Pod 无法容忍该 Node 污点,则这个 Pod 不能被调度至该 Node 上;
PreferNoSchedule:(调度期间生效)是上面的宽松版本,表示尽量阻止无法容忍该 Node 污点的 Pod 调度至该 Node 上。如果某个 Pod 无法容忍该 Node 污点,但是该 Pod 已经没有其他 Node 可以调度,那么该 Pod 依然会被调度至该 Node 上;
NoExecute:(调度及运行期间生效)若某个 Node 添加了该效果的污点,则无法容忍该污点的 Pod 将不会被调度至该 Node 上,并且该 Node 上原本已存在的 Pod 中若出现无法容忍该污点的 Pod,也会被去除;
展示案例
首先展示一个 Master 节点的 污点信息。
下面是 get nodes -o yaml
的结果:
下面是 describe nodes
的结果:
为 Node 添加污点
有两种方式可以为 Node 添加污点:
使用
kubectl taint
命令;修改 YAML 配置文件;
命令修改
为 名为 node1.k8s
的 Node 添加 node-type=production:NoSchedule
污点:
修改配置文件
在 nodes.spec.taints.key
中配置污点的 ;在 nodes.spec.taints.value
中配置污点的 ;在 nodes.spec.taints.effect
中配置污点的 :
Pod 容忍度
展示案例
下面展示一个可以运行在 Master 节点的 Pod 的容忍度信息(即容忍 Node 的 node-role.kubernetes.io/master:NoSchedule
污点)。
下面是 get pods -o yaml
的结果:
下面是 describe pods
的结果:
为 Pod 添加容忍度
可以通过 YAML 配置文件为 Pod 添加容忍度,下面展示一个例子。下面这个例子创建了一个 Deployment,其负责的 Pod 能够容忍的污点为 node-type=production:NoSchedule
、任何 key 为 CriticalAddonsOnly
的污点、任何 key 为 node.kubernetes.io/not-ready
, effect 为 NoExecute
的污点:
Last updated
Was this helpful?