江苏城乡建设职业学院网站,网站建设好的乡镇,百度公司招聘2022年最新招聘,免费网站域名空间1.前言
污点是给node节点打上污点标签#xff0c;使得pod不能往该node节点上调度#xff0c;污点有三种模式#xff0c;分别是NoSchedule、PreferNoSchedule、NoExecute#xff0c;容忍是给pod打上和node节点一样的污点标签#xff0c;使pod能调度到带有该污点标签的node…1.前言
污点是给node节点打上污点标签使得pod不能往该node节点上调度污点有三种模式分别是NoSchedule、PreferNoSchedule、NoExecute容忍是给pod打上和node节点一样的污点标签使pod能调度到带有该污点标签的node节点上
2.污点
NoSchedule禁止所有pod往该node节点上调度原本已经在节点上的pod没有影响
PreferNoSchedule尽量不将pod调度到该节点上但还是可以接受pod的调度但是pod的调度一般都会优先调度到没有污点的node上
NoExecute禁止所有pod往该node节点上调度原本已经在节点上运行的pod也将被驱逐出去
接下来使用一下以上的三个污点模式,一个节点可以被设置多个污点
kubectl taint node 节点名称 keyvalue:effect
kubectl taint node k8s-node01 webtrue:NoSchedule
kubectl taint node k8s-node02 apptrue:PreferNoSchedule
kubectl taint node k8s-node01 webtrue:NoExecute
查看节点中的污点
kubectl describe node k8s-node02 接下来说一下去除污点
删除特定的一个污点
kubectl taint node k8s-node01 webtrue:NoSchedule-
也可以不指定value去删除
kubectl taint node k8s-node02 app:PreferNoSchedule-
删除关于该key的所有污点
kubectl taint node k8s-node01 web- 3.容忍
如果一个节点有多个污点则pod必须包含该节点上的所有污点标签才可以被调度到该节点上当然了PreferNoSchedule的污点标签是不影响的接下来展示一下容忍的使用
新建一个yaml文件
vi deployment-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata: labels:app: nginxname: nginxnamespace: default
spec:replicas: 3progressDeadlineSeconds: 600minReadySeconds: 10strategy:rollingUpdate:maxSurge: 1maxUnavailable: 0type: RollingUpdateselector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec: containers:- name: nginximage: nginx:1.21imagePullPolicy: IfNotPresentports:- containerPort: 80resources:requests:memory: 50Micpu: 0.5limits:memory: 100Micpu: 1这个yaml文件中没有设置容忍接下来给node节点打上污点
kubectl taint node k8s-node01 webtrue:NoSchedule
kubectl taint node k8s-node02 key1value1:NoExecute
给两个node节点都打上了不可调度的污点现在来执行一下yaml文件看一下效果
kubectl apply -f deployment-nginx.yaml
查看一下pod的状态
kubectl get pod -o wide -n default -l appnginx 可以看到所有三个pod都是pending状态node列也显示是none说明没有适合的node给pod调度
现在更改一下yaml文件给pod加上k8s-node01的容忍策略
vi deployment-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata: labels:app: nginxname: nginxnamespace: default
spec:replicas: 3progressDeadlineSeconds: 600minReadySeconds: 10strategy:rollingUpdate:maxSurge: 1maxUnavailable: 0type: RollingUpdateselector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec: containers:- name: nginximage: nginx:1.21imagePullPolicy: IfNotPresentports:- containerPort: 80resources:requests:memory: 50Micpu: 0.5limits:memory: 100Micpu: 1tolerations: #配置容忍策略- key: web #k8s-node01中配置的污点keyoperator: Equal #Equal为等于即keyvalue使用Equal为精确匹配只有当节点上 key 的值等于 value 时才可以容忍这个 Taint还可以使用Exists模糊匹配使用Exists不用配置value值只要节点上存在对应的 key就可以容忍这个 Taintvalue: true #k8s-node01中配置的污点valueeffect: NoSchedule #k8s-node01中配置的污点effect
重新加载一下 yaml文件配置
kubectl apply -f deployment-nginx.yaml
查看一下pod的状态
kubectl get pod -o wide -n default -l appnginx 可以看到增加了k8s-node01污点的容忍策略后pod都调度到了k8s-node01节点上
容忍策略以上四个常用的配置项外还有一个配置项tolerationSeconds此配置项在污点模式为NoExecute时使用tolerationSeconds 的作用是为了在节点的 Taint 被移除之前给予一定的时间让 Pod 在该节点上运行。这对于一些需要在节点上运行一段时间的任务非常有用例如数据迁移、数据备份等