简体   繁体   English

“kubectl wait”永远等待

[英]"kubectl wait" waits forever

I'm trying to write a little shell script that is checking the log output of a long running Kubernetes Pod when the Pod is done.我正在尝试编写一个小 shell 脚本,用于在 Pod 完成后检查长时间运行的 Kubernetes Pod 的日志输出。

The script shall wait for status "Completed" but the following command does not exit when the status is switching from "Running" to "Completed":脚本应等待状态“已完成”,但当状态从“正在运行”切换到“已完成”时,以下命令不会退出:

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

^C ^C

$ kubectl get pods $ kubectl 获取豆荚

NAME READY STATUS RESTARTS AGE姓名准备状态重新开始年龄

longrunningpodname 0/1 Completed 0 18h longrunningpodname 0/1 已完成 0 18h

I would also expect the command to return immediately if the Pod is already in the status.如果 Pod 已经处于状态,我还希望命令立即返回。 But that doesn't happen.但这不会发生。

Is kubectl wait not the command I'm looking for? kubectl wait 不是我要找的命令吗?

The use of bare pods is not the best approach to run commands that must finish.使用裸 Pod 并不是运行必须完成的命令的最佳方法。 Consider using a Job Controller :考虑使用作业控制器

A Job creates one or more Pods and ensures that a specified number of them successfully terminate.一个 Job 创建一个或多个 Pod 并确保指定数量的 Pod 成功终止。 As pods successfully complete, the Job tracks the successful completions.当 pod 成功完成时,Job 会跟踪成功完成情况。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM