k8s 集群中可能管理著非常龐大的服務(wù)器,這些服務(wù)器可能是各種各樣不同類型的,比如機(jī)房、地理位置、配置等,有些是計(jì)算型節(jié)點(diǎn),有些是存儲(chǔ)型節(jié)點(diǎn),此時(shí)我們希望能更好的將 pod 調(diào)度到與之需求更匹配的節(jié)點(diǎn)上。
此時(shí)就需要用到污點(diǎn)(Taint)和容忍(Toleration),這些配置都是 key: value 類型
1 污點(diǎn)
標(biāo)注在節(jié)點(diǎn)上,當(dāng)我們在一個(gè)節(jié)點(diǎn)上打上污點(diǎn)以后,k8s 會(huì)認(rèn)為盡量不要將 pod 調(diào)度到該節(jié)點(diǎn)上,除非該 pod 上面表示可以容忍該污點(diǎn),且一個(gè)節(jié)點(diǎn)可以打多個(gè)污點(diǎn),此時(shí)則需要 pod 容忍所有污點(diǎn)才會(huì)被調(diào)度該節(jié)點(diǎn)
1.1 使用
# 為節(jié)點(diǎn)打上污點(diǎn)
kubectl taint node k8s-master key=value:NoSchedule
#example:為k8s-node1打上一個(gè)污點(diǎn),表示內(nèi)存低,造成影響為NoSchedule
kubectl taint node k8s-node1 memory=low:NoSchedule
# 移除污點(diǎn)
kubectl taint node k8s-master key=value:NoSchedule-
# 查看污點(diǎn)
kubectl describe no k8s-master
1.2?污點(diǎn)的影響
-
NoSchedule
不能容忍的 pod 不能被調(diào)度到該節(jié)點(diǎn),但是已經(jīng)存在的節(jié)點(diǎn)不會(huì)被驅(qū)逐
-
PreferNoSchedule
盡量不要部署到有該污點(diǎn)的節(jié)點(diǎn)上
-
NoExecute
-
不能容忍的節(jié)點(diǎn)會(huì)被立即清除
-
能容忍且沒有配置 tolerationSeconds 屬性,則可以一直運(yùn)行
-
設(shè)置了 tolerationSeconds: 3600 屬性,則該 pod 還能繼續(xù)在該節(jié)點(diǎn)運(yùn)行 3600 秒
-
2?容忍
是標(biāo)注在 pod 上的,當(dāng) pod 被調(diào)度時(shí),如果沒有配置容忍,則該 pod 不會(huì)被調(diào)度到有污點(diǎn)的節(jié)點(diǎn)上,只有該 pod 上標(biāo)注了滿足某個(gè)節(jié)點(diǎn)的所有污點(diǎn),則會(huì)被調(diào)度到這些節(jié)點(diǎn)
# pod 的 spec 下面配置容忍
tolerations:
- key: "污點(diǎn)的 key"
value: "污點(diǎn)的 value"
offect: "NoSchedule" # 污點(diǎn)產(chǎn)生的影響
operator: "Equal" # 表是 value 與污點(diǎn)的 value 要相等,也可以設(shè)置為 Exists 表示存在 key 即可,此時(shí)可以不用配置 value
operator設(shè)置:與污點(diǎn)進(jìn)行匹配的規(guī)則
-
Equal:對(duì)比key和value都相等
-
Exists:只對(duì)比key,只要key存在即可,此時(shí)可以不用配置value文章來源:http://www.zghlxwxcb.cn/news/detail-625736.html
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
tolerations: # 配置容忍
- key: "node" # 污點(diǎn)的key
value: "slave" # 污點(diǎn)的value
operator: "Exists" # 容忍操作
effect: "NoSchedule" # 容忍效果
tolerationSeconds: 6000
?文章來源地址http://www.zghlxwxcb.cn/news/detail-625736.html
到了這里,關(guān)于k8s概念-污點(diǎn)與容忍的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!