This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.4.7.2. 添加污点和容限
您可以为 pod 和污点添加容限,以便节点能够控制哪些 pod 应该或不应该调度到节点上。对于现有的 pod 和节点,您应首先将容限添加到 pod,然后将污点添加到节点,以避免在添加容限前从节点上移除 pod。
流程
通过编辑
Pod
spec 使其包含tolerations
小节来向 pod 添加容限:使用 Equal 运算符的 pod 配置文件示例
spec: .... template: .... spec: tolerations: - key: "key1" value: "value1" operator: "Equal" effect: "NoExecute" tolerationSeconds: 3600
spec: .... template: .... spec: tolerations: - key: "key1"
1 value: "value1" operator: "Equal" effect: "NoExecute" tolerationSeconds: 3600
2 Copy to Clipboard Copied! 例如:
使用 Exists 运算符的 pod 配置文件示例
spec: .... template: .... spec: tolerations: - key: "key1" operator: "Exists" effect: "NoExecute" tolerationSeconds: 3600
spec: .... template: .... spec: tolerations: - key: "key1" operator: "Exists"
1 effect: "NoExecute" tolerationSeconds: 3600
Copy to Clipboard Copied! - 1
Exists
运算符不会接受一个value
。
本例在
node1
上放置一个键为key1
且值为value1
的污点,污点效果是NoExecute
。通过以下命令,使用 Taint 和 toleration 组件表中描述的参数为节点添加污点:
oc adm taint nodes <node_name> <key>=<value>:<effect>
$ oc adm taint nodes <node_name> <key>=<value>:<effect>
Copy to Clipboard Copied! 例如:
oc adm taint nodes node1 key1=value1:NoExecute
$ oc adm taint nodes node1 key1=value1:NoExecute
Copy to Clipboard Copied! 此命令在
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 ...
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 ...
Copy to Clipboard Copied! pod 上的容限与节点上的污点匹配。具有任一容限的 pod 可以调度到
node1
上。