-
作者: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:NoSchedulekubectl taint nodes k8s-node1 key1=value1:NoExecutekubectl 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
tolerations
和containers
同级。key
能容忍的污点key
。operator
Equal
等于示意key=value
,Exists
不等于,示意当值不等于上面value
失常value
能够设置为NoSchedule
、PreferNoSchedule
或NoExecute
。effect
effect
策略tolerationSeconds
是当 pod 须要被驱赶时,能够持续在 node 上运行的工夫。
具体的应用办法请参考官网文档。
-
作者:SRE运维博客
博客地址: https://www.cnsre.cn/
文章地址:https://www.cnsre.cn/posts/211129946481/
相干话题:https://www.cnsre.cn/tags/kubernetes/
- -