Kubectl 运行带有节点选择器和容忍度的命令

问题描述 投票:0回答:2

我正在使用 Kubectl run 命令在特定节点上执行 pod。

kubectl --namespace=ns run pod1 --image image1 \
  --overrides='{"spec":{"nodeSelector":{"appgroup":"app1"}}}' \
  --command python3 script.py

有时 pod 会处于挂起状态,无法进入运行阶段。

如何向运行命令添加容差?

注意:我没有 yaml 文件。

如有任何帮助,我们将不胜感激

python kubernetes kubectl
2个回答
4
投票

您可以通过添加“tolerations”数组来完成此操作。

如果您想忽略所有容忍,我们可以使用“operator=exists”条件来做到这一点。

kubectl --namespace=$your_ns run $your_pod --image $your_image \
  --overrides='{"spec":{"nodeSelector":{"appgroup":"app1"},"tolerations":[{"operator":"exists"}]}}' \
  --command python3 script.py \
  [--dry-run=client -o yaml]

另请注意:如果您想使用 YAML 文件,“dry-run”和“-o yaml”选项将帮助您生成第一个副本。也许您会更喜欢使用纯文本文件来测试您的更改。


0
投票

此处给出的答案https://stackoverflow.com/a/74251366/6070499是正确的。然而,必须将

exists
更改为
Exists
(当时我在 Stackoverflow 上没有足够的声誉来建议编辑) 否则您将收到
spec.tolerations[0].operator: Unsupported value: "exists": supported values: "Equal", "Exists"
错误

© www.soinside.com 2019 - 2024. All rights reserved.