"kubectl wait"永远等待

"kubectl wait" waits forever

我正在尝试编写一个小 shell 脚本,用于在 Pod 完成后检查长 运行 Kubernetes Pod 的日志输出。

脚本应等待状态“已完成”,但当状态从“运行”切换到“已完成”时,以下命令不会退出:

$ kubectl wait --for=condition=Completed --timeout=24h pod/longrunningpodname

^C

$ kubectl get pods

NAME READY STATUS RESTARTS AGE

longrunningpodname 0/1 Completed 0 18h

如果 Pod 已处于状态,我还希望命令立即 return。但这并没有发生。

kubectl wait 不是我要找的命令吗?

使用裸 pods 并不是必须完成 运行 命令的最佳方法。考虑使用 Job Controller:

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions.

然后,您可以等待工作条件:
kubectl wait --for=condition=complete --timeout=24h job/longrunningjobname