污點 》》 節點上
容忍度 》》 Pod上
在K8S中,如果Pod能容忍某個節點上的污點,那么Pod就可以調度到該節點。如果不能容忍,那就無法調度到該節點。
污點和容忍度的概念
》》污點等級——>node
》》容忍度 —>pod
Equal——>一種是等值匹配
Exitst——>一種是存在性匹配;
# 污點定義在節點的nodeSpec中,容忍度定義在Pod的podSpec中。# 污點和容忍度都是鍵值對的數據格式,但是要增加一個排斥等級(effect)標記。
# 排斥等級 NoSchedule 、 NoExecute 、PreferNoSchedule
語法格式為:"key=value:effect"
## 使用Equal的場景:
tolerations:
- key: "key"operator: "Equal"value: "value"effect: "NoExecute"
## 使用Exists的場景:
tolerations:
- key: "key"operator: "Exists"effect: "NoExecute"#如果Node上污點的排斥等級是NoExecute時,該Node上正在運行的Pod如果沒有該污點的容忍度,就會被立刻驅逐。不過系統增加了tolerationSeconds字段,用來延遲驅逐Pod。# tolerationSeconds字段的意思是:如果 Pod 的容忍度配置里存在排斥等級為 NoExecute ,并且指定了屬性 tolerationSeconds 的值,那么Pod 還能繼續在該節點上運行的時間(單位為秒):tolerations:
- key: "key"operator: "Equal"value: "value"effect: "NoExecute"tolerationSeconds: 3600```csharp
# 定義污點語法
# node-name:指定需要打污點的Node主機名
# key=value:指定污點的鍵值型數據 effect:為污點的等級
# kubectl taint nodes node01 key=value:effect
kubectl taint nodes <node-name> <key>=<value>:<effect>
# 添加污點 為k8s-node02添加污點,污點程度為NoSchedule,type=calculate為標簽
kubectl taint nodes k8s-node2 type=calculate:NoSchedule# 查看污點
kubectl describe nodes k8s-node2 | grep Taints# 刪除污點 刪除污點之需要指定標簽的 **key** 及污點程度
# kubectl taint nodes node01 key[:effect]-
kubectl taint node k8s-node2 type:NoSchedule-
容忍度介紹及定義
Pod對象的容忍度可以通過其spec.tolerations字段進行添加,根據使用的操作符不同,主要有兩種可用的形式:
容忍度與污點信息完全匹配的等值關系,使用Equal操作符。
判斷污點是否存在的匹配方式,使用Exists操作富。
容忍度所用到的參數tolerations,tolerations參數下的還有以下幾個二級參數:
operator:此值被稱為運算符,值可以為[Equal|Exists],Equal表示污點的key是否等于value(默認參數),Exists只判斷污點的key是否存在,使用該參數時,不需要定義value。
effect:指定匹配的污點程度,為空表示匹配所有等級的污點,值可以為 [NoSchedule|PreferNoSchedule|NoExecut]。
key:指定Node上污點的鍵key。
value:指定Node上污點的值value。
tolerationSeconds:用于定于延遲驅趕當前Pod對象的時長,如果設置為0或者負值系統將立即驅趕當前Pod。(單位為秒)
apiVersion: v1
kind: Pod
metadata:name: webappnamespace: demolabels:app: webapp
spec:nodeSelector:# 選擇調度到具有這個label的節點"special-app": "specialwebapp"# 容忍度tolerations:- key: "question-node"operator: "Equal"value: "broken-disk"effect: "NoSchedule"containers:- name: webappimage: nginxports:- containerPort: 80