kubernetes污点和容忍
kubernetes污点和容忍
https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
https://kubernetes.io/zh/docs/concepts/configuration/taint-and-toleration/
Node affinity
用来引导pod调度到合适的node上;Taint
和 Toleration
则相反,它们使node能够排斥或者驱逐一类特定的pod。
Taint 和 toleration 配对使用,可以用来避免 pod 被分配到不合适的节点上:
Taint:不能调度
toleration:尽量不要
增加和删除污点:
样式:kubectl taint nodes node1 key=value:effect
例如:
#除非有相应的容忍,没有pod能够调度到node1上
kubectl taint nodes node1 key1=value1:NoSchedule
#尽量避免将没有容忍的pod调度到node1上
kubectl taint nodes node1 key1=value1:PreferNoSchedule
#已经在node1上运行的pod会被从node上驱逐掉,切不会有新pod调度上来
kubectl taint nodes node1 key1=value1:NoExecute
#删除
kubectl taint nodes node1 key:NoSchedule-
kubectl taint node node01 node-role.kubernetes.io/master- master节点参与调度
kubectl taint node node01 node-role.kubernetes.io/master="" master节点不参与调度
pod上的容忍:
pod上的toleration与node的Taint匹配,除了key和effect,还必须满足以下任意条件:
the operator is Exists (in which case no value should be specified)
tolerations:
- key: "key"
operator: "Exists"
effect: "NoSchedule"
the operator is Equal and the values are equal
tolerations:
- key: "key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
例如:
tolerations:
- key: "key1"
operator: "Equal"
value: "value1"
effect: "NoExecute"
#跑3600s后再被踢掉
tolerationSeconds: 3600
1、kubectl taint node k8s-master node-role.kubernetes.io/master=true:NoSchedule
2、kubectl cordon k8s-master