Taints(污點(diǎn)):避免Pod調(diào)度到特定的Node上
Tolerations(污點(diǎn)容忍): 允許Pod調(diào)度到持有Taints的Node上
應(yīng)用場(chǎng)景:
? 專(zhuān)用節(jié)點(diǎn):根據(jù)業(yè)務(wù)線(xiàn)將Node分組管理痴腌,希望在默認(rèn)情況下不調(diào)度該節(jié)點(diǎn)长豁,只有配置了污點(diǎn)容忍才允許分配
? 配備特殊硬件:部分Node配有SSD硬盤(pán),GPU,希望在默認(rèn)情況下不調(diào)度該節(jié)點(diǎn),只有配置了污點(diǎn)容忍才允許分配
? 基于Taint的驅(qū)逐
污點(diǎn)配置:
給node節(jié)點(diǎn)添加污點(diǎn)
kubectl taint node [node] key=value:[effect]
其中key=value 是設(shè)定一個(gè)污點(diǎn)標(biāo)簽
其中[effect] 可取值:
? NoSchedule :一定不能被調(diào)度
? PreferNoSchedule:盡量不要調(diào)度胎许,非必須配置容忍
? NoExecute:不僅不會(huì)調(diào)度,還會(huì)驅(qū)逐Node上已有的Pod
污點(diǎn)容忍配置:
在pod.yaml中添加配置(spec下級(jí)颂碘,和containers段同級(jí))
tolerations:
- key: "gpu" #允許容忍的污點(diǎn)標(biāo)簽key(添加節(jié)點(diǎn)污點(diǎn)時(shí)指定的)
operator: "Equal" #操作符坯门,equal等于
value: "yes" #允許容忍的污點(diǎn)標(biāo)簽value(添加節(jié)點(diǎn)污點(diǎn)時(shí)指定的)
effect: "NoSchedule" #effect (添加節(jié)點(diǎn)污點(diǎn)時(shí)指定的)
去掉污點(diǎn)
kubectl taint node [node] key-
例子:
- 一共2臺(tái)node節(jié)點(diǎn),給node1 和 node2 都打上污點(diǎn)挡闰。分別指定兩個(gè)污點(diǎn)標(biāo)簽gpu=yes,disk=ssd乒融,最后查看pod狀態(tài)和污點(diǎn)狀態(tài)
kubectl taint node k8s-node1 gpu=yes:NoSchedule
kubectl taint node k8s-node2 disk=ssd:NoSchedule
#創(chuàng)建個(gè)pod
kubectl apply -f pod_taint.yaml
上述結(jié)果說(shuō)明,污點(diǎn)配置成功摄悯,node1和node2都被打上了污點(diǎn)赞季,當(dāng)前已無(wú)合適的node可分配了。
-
如果在特殊情況下奢驯,需要污點(diǎn)機(jī)器也可以被分配申钩,就要配置污點(diǎn)容忍。 在上面的情況下瘪阁,如果讓node1還能繼續(xù)被分配撒遣,在pod.yaml添加
image.png
再次創(chuàng)建pod,發(fā)現(xiàn)成功分配到了管跺。驗(yàn)證Tolerations
- 最后再去掉這兩臺(tái)node的污點(diǎn)
kubectl taint node k8s-node1 gpu-
#node/k8s-node1 untainted
kubectl taint node k8s-node2 disk-
#node/k8s-node2 untainted
kubectl describe node|grep Taint
Taints: node-role.kubernetes.io/master:NoSchedule
Taints: <none>
Taints: <none>