简体   繁体   中英

"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.

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

^C

$ kubectl get pods

NAME READY STATUS RESTARTS AGE

longrunningpodname 0/1 Completed 0 18h

I would also expect the command to return immediately if the Pod is already in the status. But that doesn't happen.

Is kubectl wait not the command I'm looking for?

The use of bare pods is not the best approach to run commands that must finish. Consider using a 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.

Then, you can wait for the job condition:
kubectl wait --for=condition=complete --timeout=24h job/longrunningjobname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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