kubectl wait --for=条件=完成 --timeout=30s

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

我正在尝试通过此文档使用 kubectl wait 命令检查 pod 的状态。 以下是我正在尝试的命令

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1-oo-9j9kj

以下是我遇到的错误

Kubectl error: status.conditions accessor error: Failure is of the type string, expected map[string]interface{}

我的

kubectl -o json
输出可以通过这个githublink访问。

有人可以帮我解决这个问题吗

kubernetes kubectl
4个回答
57
投票

要等到 Pod 运行,请检查“condition=ready”。另外,更喜欢按标签过滤,而不是指定 pod id。例如:

$ kubectl wait --for=condition=ready pod -l app=netshoot 
pod/netshoot-58785d5fc7-xt6fg condition met

另一个选项是 rollout status - 等待部署完成:

$ kubectl rollout status deployment netshoot
deployment "netshoot" successfully rolled out

当需要等待应用程序安装时,这两个选项在自动化脚本中都非常有效。然而,正如 @CallMeLaNN 对第二个选项指出的那样,“推出”的部署不一定没有错误。


18
投票

这完全看起来像是您在

Pod
上运行 kubectl wait --for=condition=complete,如输出中所述,而不是 Job

pod 没有

--for=condition=complete
选项。确切地说,当我在 Pod 上运行它时我得到了什么:

$ kubectl wait --for=condition=complete pod/mypod-xxxxxxxxxx-xxxxx
error: .status.conditions accessor error: Failure is of the type string, expected map[string]interface{}

3
投票

正如 Rico 所概述的,你不能等待 pod 上的完整状态,假设你想等待作业完成,请使用以下

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1

0
投票

即使 --for=condition=complete 不存在,您也可以使用 --for=condition=ready=False

这将等到您的 Pod 停止运行,这似乎正是您想要的。至少,它对我有用。

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