kubectl wait --for=condition=complete --timeout=30s

Aut*_*ner 22 kubernetes kubectl

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

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1-oo-9j9kj
Run Code Online (Sandbox Code Playgroud)

以下是我得到的错误

Kubectl error: status.conditions accessor error: Failure is of the type string, expected map[string]interface{}
Run Code Online (Sandbox Code Playgroud)

和我的kubectl -o json output can be accessed via this github 链接

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

Noa*_*nos 17

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

$ kubectl wait --for=condition=ready pod -l app=netshoot 
pod/netshoot-58785d5fc7-xt6fg condition met
Run Code Online (Sandbox Code Playgroud)

另一个选项是推出状态- 等到部署完成:

$ kubectl rollout status deployment netshoot
deployment "netshoot" successfully rolled out
Run Code Online (Sandbox Code Playgroud)

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

  • 根据您的经验,上述“kubectl wait --for=condition=ready”有任何问题吗?我觉得不太靠谱。有时,即使“kubectl get pods”返回就绪,应用/推出重新启动后也会超时。 (2认同)

Ric*_*ico 14

这完全看起来像是您在输出中描述kubectl wait --for=condition=completePod而不是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{}
Run Code Online (Sandbox Code Playgroud)


Dan*_*son 5

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

kubectl wait --for=condition=complete --timeout=30s -n d1 job/test-job1
Run Code Online (Sandbox Code Playgroud)