Taint(污點)和 Toleration(容忍)可以作用于 node 和 pod 上既峡,其目的是優(yōu)化 pod 在集群間的調(diào)度,這跟節(jié)點親和性類似,只不過它們作用的方式相反崎溃,具有 taint 的 node 和 pod 是互斥關系,而具有節(jié)點親和性關系的 node 和 pod 是相吸的盯质。另外還有可以給 node 節(jié)點設置 label袁串,通過給 pod 設置 nodeSelector
將 pod 調(diào)度到具有匹配標簽的節(jié)點上。
Taint 和 toleration 相互配合呼巷,可以用來避免 pod 被分配到不合適的節(jié)點上囱修。每個節(jié)點上都可以應用一個或多個 taint ,這表示對于那些不能容忍這些 taint 的 pod王悍,是不會被該節(jié)點接受的破镰。如果將 toleration 應用于 pod 上,則表示這些 pod 可以(但不要求)被調(diào)度到具有相應 taint 的節(jié)點上。
示例
以下分別以為 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
的值可以為NoSchedule
孕似、PreferNoSchedule
或NoExecute
瓶佳。 -
tolerationSeconds
是當 pod 需要被驅(qū)逐時,可以繼續(xù)在 node 上運行的時間鳞青。
詳細使用方法請參考官方文檔霸饲。