16.11.4. 在 Pod 中添加容限
要为 pod 添加容限,请编辑 pod 规格使其包含 tolerations 部分:
使用 Equal 运算符的 pod 配置文件示例
- 1 2 3 4
- 容限参数,如 Taint 和 toleration 组件表中所述。
- 5
tolerationSeconds参数指定 pod 在被驱除前可以保持与节点绑定的时长。请参阅以下 使用 Toleration seconds to Delay Pod 驱除。
使用 Exists 运算符的 pod 配置文件示例
tolerations: - key: "key1" operator: "Exists" effect: "NoExecute" tolerationSeconds: 3600
tolerations:
- key: "key1"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 3600
这两个容限都与 以上 oc adm taint 命令创建 的污点匹配。具有任一容限的 pod 可以调度到 node1。
16.11.4.1. 使用 Toleration Seconds 延迟 Pod 驱除 复制链接链接已复制到粘贴板!
您可以通过在 pod 规格中指定 tolerationSeconds 参数,指定 pod 在被驱除前可以保持与节点绑定的时长。如果将具有 NoExecute effect 的污点添加到某个节点,则所有不容许该污点的 pod 都被立即驱除(容许该污点的 pod 不会被驱除)。但是,如果要被驱除的 pod 具有 tolerationSeconds 参数,则只有该时限到期后 pod 才会被驱除。
例如:
在这里,如果此 pod 正在运行但没有匹配的污点,pod 保持与节点绑定 3600 秒,然后被驱除。如果污点在这个时间之前移除,pod 就不会被驱除。
16.11.4.1.1. 为 Toleration second 设置默认值 复制链接链接已复制到粘贴板!
此插件为 pod 设置默认的强制容限,以容忍 node.kubernetes.io/not-ready:NoExecute 和 node.kubernetes.io/unreachable:NoExecute 污点为五分钟。
如果用户提供的 pod 配置已具有任一容限,则不会添加默认值。
启用 Default Toleration seconds:
将 master 配置文件(/etc/origin/master/master-config.yaml)修改为将
DefaultTolerationSeconds添加到 admissionConfig 部分:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重启 OpenShift 以使更改生效:
master-restart api master-restart controllers
# master-restart api # master-restart controllersCopy to Clipboard Copied! Toggle word wrap Toggle overflow 验证是否已添加默认值:
创建 pod:
oc create -f </path/to/file>
$ oc create -f </path/to/file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow 例如:
oc create -f hello-pod.yaml
$ oc create -f hello-pod.yaml pod "hello-pod" createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow 检查 pod 容限:
oc describe pod <pod-name> |grep -i toleration
$ oc describe pod <pod-name> |grep -i tolerationCopy to Clipboard Copied! Toggle word wrap Toggle overflow 例如:
oc describe pod hello-pod |grep -i toleration
$ oc describe pod hello-pod |grep -i toleration Tolerations: node.kubernetes.io/not-ready=:Exists:NoExecute for 300sCopy to Clipboard Copied! Toggle word wrap Toggle overflow