污點、容忍度
- 給了節(jié)點選則的主動權(quán),我們給節(jié)點打一個污點,不容忍的pod就運行不上來,污點就是定義在節(jié)點上的鍵值屬性數(shù)據(jù),可以定決定拒絕那些pod;
- taints是鍵值數(shù)據(jù),用在節(jié)點上,定義污點;
- tolerations是鍵值數(shù)據(jù),用在pod上,定義容忍度,能容忍哪些污點
- pod親和性是pod屬性;但是污點是節(jié)點的屬性,污點定義在k8s集群的節(jié)點上的一個字段
kubectl explain node.spec.taints
KIND: Node
VERSION: v1
RESOURCE: taints <[]Object>
DESCRIPTION:
If specified, the node's taints.
The node this Taint is attached to has the "effect" on any pod that does
not tolerate the Taint.
FIELDS:
effect <string> -required-
key <string> -required-
timeAdded <string>
value <string>
taints的effect用來定義對pod對象的排斥等級(效果):
NoSchedule:
僅影響pod調(diào)度過程,當(dāng)pod能容忍這個節(jié)點污點,就可以調(diào)度到當(dāng)前節(jié)點,后來這個節(jié)點的污點改了,加了一個新的污點,使得之前調(diào)度的pod不能容忍了,那這個pod會怎么處理,對現(xiàn)存的pod對象不產(chǎn)生影響
NoExecute:
既影響調(diào)度過程,又影響現(xiàn)存的pod對象,如果現(xiàn)存的pod不能容忍節(jié)點后來加的污點,這個pod就會被驅(qū)逐
PreferNoSchedule:
最好不,也可以,是NoSchedule的柔性版本
查看master這個節(jié)點是否有污點,顯示如下:
kubectl describe nodes k8smaster1
Taints: node-role.kubernetes.io/control-plane:NoSchedule
上面可以看到master這個節(jié)點的污點是Noschedule
所以我們創(chuàng)建的pod都不會調(diào)度到master上,因為我們創(chuàng)建的pod沒有容忍度
kubectl describe pods kube-apiserver-k8smaster1 -n kube-system
顯示如下:
Tolerations: :NoExecute op=Exists
可以看到這個pod的容忍度是NoExecute,則可以調(diào)度到k8smaster1上
管理節(jié)點污點
kubectl taint –help
把k8snode2當(dāng)成是生產(chǎn)環(huán)境專用的,其他node是測試的
給k8snode2打污點,pod如果不能容忍就不會調(diào)度過來
kubectl taint node k8snode2 node-type=production:NoSchedule
vim pod-taint.yaml
apiVersion: v1
kind: Pod
metadata:
name: taint-pod
namespace: default
labels:
tomcat: tomcat-pod
spec:
containers:
- name: taint-pod
ports:
- containerPort: 8080
image: tomcat:8.5-jre8-alpine
imagePullPolicy: IfNotPresent
kubectl apply -f pod-taint.yaml
kubectl get pods -o wide
顯示如下:
taint-pod running k8snode1
可以看到都被調(diào)度到k8snode1上了,因為k8snode2這個節(jié)點打了污點,而我們在創(chuàng)建pod的時候沒有容忍度,所以k8snode2上不會有pod調(diào)度上去的
給k8snode1也打上污點
kubectl taint node k8snode1 node-type=dev:NoExecute
kubectl get pods -o wide
顯示如下:可以看到已經(jīng)存在的pod節(jié)點都被攆走了
taint-pod termaitering
vim pod-demo-1.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-deploy
namespace: default
labels:
app: myapp
release: canary
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
tolerations:
- key: "node-type"
operator: "Equal"
value: "production"
effect: "NoExecute"
tolerationSeconds: 3600
kubectl apply -f pod-demo-1.yaml
kubectl get pods
myapp-deploy 1/1 Pending 0 11s k8snode2
還是顯示pending,因為我們使用的是equal(等值匹配),所以key和value,effect必須和node節(jié)點定義的污點完全匹配才可以,把上面配置effect: "NoExecute"變成effect: “NoSchedule”;
tolerationSeconds: 3600這行去掉
修改后重新生成pod
kubectl delete -f pod-demo-1.yaml
kubectl apply -f pod-demo-1.yaml
kubectl get pods
myapp-deploy 1/1 running 0 11s k8snode2
上面就可以調(diào)度到k8snode2上了,因為在pod中定義的容忍度能容忍node節(jié)點上的污點文章來源:http://www.zghlxwxcb.cn/news/detail-656351.html
刪除污點:文章來源地址http://www.zghlxwxcb.cn/news/detail-656351.html
kubectl taint nodes xianchaonode1 node-type:NoExecute-
kubectl taint nodes xianchaonode2 node-type-
到了這里,關(guān)于學(xué)習(xí)筆記十八:污點、容忍度的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!