3.6.2. 添加污点和容限
您可以为 pod 和污点添加容限,以便节点能够控制哪些 pod 应该或不应该调度到节点上。对于现有的 pod 和节点,您应首先将容限添加到 pod,然后将污点添加到节点,以避免在添加容限前从节点上移除 pod。
流程
通过编辑
Podspec 使其包含tolerations小节来向 pod 添加容限:使用 Equal 运算符的 pod 配置文件示例
spec: .... template: .... spec: tolerations: - key: "key1"1 value: "value1" operator: "Equal" effect: "NoExecute" tolerationSeconds: 36002 例如:
使用 Exists 运算符的 pod 配置文件示例
spec: .... template: .... spec: tolerations: - key: "key1" operator: "Exists"1 effect: "NoExecute" tolerationSeconds: 3600- 1
Exists运算符不会接受一个value。
本例在
node1上放置一个键为key1且值为value1的污点,污点效果是NoExecute。通过以下命令,使用 Taint 和 toleration 组件表中描述的参数为节点添加污点:
$ oc adm taint nodes <node_name> <key>=<value>:<effect>例如:
$ oc adm taint nodes node1 key1=value1:NoExecute此命令在
node1上放置一个键为key1,值为value1的污点,其效果是NoExecute。注意如果为 control plane 节点(也称为 master 节点)添加了一个
NoSchedule污点,则节点必须具有node-role.kubernetes.io/master=:NoSchedule污点,该污点会被默认添加。例如:
apiVersion: v1 kind: Node metadata: annotations: machine.openshift.io/machine: openshift-machine-api/ci-ln-62s7gtb-f76d1-v8jxv-master-0 machineconfiguration.openshift.io/currentConfig: rendered-master-cdc1ab7da414629332cc4c3926e6e59c ... spec: taints: - effect: NoSchedule key: node-role.kubernetes.io/master ...pod 上的容限与节点上的污点匹配。具有任一容限的 pod 可以调度到
node1上。
3.6.2.1. 使用机器集添加污点和容限 复制链接链接已复制到粘贴板!
您可以使用机器集为节点添加污点。与 MachineSet 对象关联的所有节点都会使用污点更新。容限对由机器集添加的污点的处理方式与直接添加到节点的污点的处理方式相同。
流程
通过编辑
Podspec 使其包含tolerations小节来向 pod 添加容限:使用
Equal运算符的 pod 配置文件示例spec: .... template: .... spec: tolerations: - key: "key1"1 value: "value1" operator: "Equal" effect: "NoExecute" tolerationSeconds: 36002 例如:
使用
Exists运算符的 pod 配置文件示例spec: tolerations: - key: "key1" operator: "Exists" effect: "NoExecute" tolerationSeconds: 3600将污点添加到
MachineSet对象:为您想要污点的节点编辑
MachineSetYAML,也可以创建新MachineSet对象:$ oc edit machineset <machineset>将污点添加到
spec.template.spec部分:机器集规格中的污点示例
spec: .... template: .... spec: taints: - effect: NoExecute key: key1 value: value1 ....本例在节点上放置一个键为
key1,值为value1的污点,污点效果是NoExecute。将机器缩减为 0:
$ oc scale --replicas=0 machineset <machineset> -n openshift-machine-api等待机器被删除。
根据需要扩展机器设置:
$ oc scale --replicas=2 machineset <machineset> -n openshift-machine-api等待机器启动。污点添加到与
MachineSet对象关联的节点上。