污点 》》 节点上
容忍度 》》 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