沈阳网站建设开发维护,九里徐州网站开发,网站远程图片,游戏工作室加盟污点、容忍度 污点、容忍度管理节点污点把k8snode2当成是生产环境专用的#xff0c;其他node是测试的给k8snode1也打上污点 污点、容忍度
给了节点选则的主动权#xff0c;我们给节点打一个污点#xff0c;不容忍的pod就运行不上来#xff0c;污点就是定义在节点上的键值属… 污点、容忍度 污点、容忍度管理节点污点把k8snode2当成是生产环境专用的其他node是测试的给k8snode1也打上污点 污点、容忍度
给了节点选则的主动权我们给节点打一个污点不容忍的pod就运行不上来污点就是定义在节点上的键值属性数据可以定决定拒绝那些podtaints是键值数据用在节点上定义污点tolerations是键值数据用在pod上定义容忍度能容忍哪些污点pod亲和性是pod属性但是污点是节点的属性污点定义在k8s集群的节点上的一个字段
kubectl explain node.spec.taintsKIND: Node
VERSION: v1
RESOURCE: taints []Object
DESCRIPTION:If specified, the nodes taints.The node this Taint is attached to has the effect on any pod that doesnot tolerate the Taint.
FIELDS:effect string -required-key string -required-timeAdded stringvalue stringtaints的effect用来定义对pod对象的排斥等级效果NoSchedule
仅影响pod调度过程当pod能容忍这个节点污点就可以调度到当前节点后来这个节点的污点改了加了一个新的污点使得之前调度的pod不能容忍了那这个pod会怎么处理对现存的pod对象不产生影响NoExecute
既影响调度过程又影响现存的pod对象如果现存的pod不能容忍节点后来加的污点这个pod就会被驱逐PreferNoSchedule
最好不也可以是NoSchedule的柔性版本查看master这个节点是否有污点显示如下 kubectl describe nodes k8smaster1Taints: node-role.kubernetes.io/control-plane:NoSchedule上面可以看到master这个节点的污点是Noschedule 所以我们创建的pod都不会调度到master上因为我们创建的pod没有容忍度 kubectl describe pods kube-apiserver-k8smaster1 -n kube-system显示如下 Tolerations: :NoExecute opExists可以看到这个pod的容忍度是NoExecute则可以调度到k8smaster1上 管理节点污点
kubectl taint –help把k8snode2当成是生产环境专用的其他node是测试的 给k8snode2打污点pod如果不能容忍就不会调度过来 kubectl taint node k8snode2 node-typeproduction:NoSchedulevim pod-taint.yaml apiVersion: v1
kind: Pod
metadata:name: taint-podnamespace: defaultlabels:tomcat: tomcat-pod
spec:containers:- name: taint-podports:- containerPort: 8080image: tomcat:8.5-jre8-alpine
imagePullPolicy: IfNotPresent kubectl apply -f pod-taint.yamlkubectl get pods -o wide 显示如下 taint-pod running k8snode1可以看到都被调度到k8snode1上了因为k8snode2这个节点打了污点而我们在创建pod的时候没有容忍度所以k8snode2上不会有pod调度上去的 给k8snode1也打上污点
kubectl taint node k8snode1 node-typedev:NoExecutekubectl get pods -o wide 显示如下可以看到已经存在的pod节点都被撵走了 taint-pod termaiteringvim pod-demo-1.yaml apiVersion: v1
kind: Pod
metadata:name: myapp-deploynamespace: defaultlabels:app: myapprelease: canary
spec:containers:- name: myappimage: ikubernetes/myapp:v1imagePullPolicy: IfNotPresentports:- name: httpcontainerPort: 80tolerations:- key: node-typeoperator: Equalvalue: productioneffect: NoExecutetolerationSeconds: 3600kubectl apply -f pod-demo-1.yamlkubectl get podsmyapp-deploy 1/1 Pending 0 11s k8snode2还是显示pending因为我们使用的是equal等值匹配所以key和valueeffect必须和node节点定义的污点完全匹配才可以把上面配置effect: NoExecute变成effect: “NoSchedule” tolerationSeconds: 3600这行去掉 修改后重新生成pod kubectl delete -f pod-demo-1.yaml
kubectl apply -f pod-demo-1.yamlkubectl get podsmyapp-deploy 1/1 running 0 11s k8snode2上面就可以调度到k8snode2上了因为在pod中定义的容忍度能容忍node节点上的污点 删除污点 kubectl taint nodes xianchaonode1 node-type:NoExecute-
kubectl taint nodes xianchaonode2 node-type-