"kubectl wait" waits forever

3/22/2019

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?

-- Simon
kubectl
kubernetes

1 Answer

3/22/2019

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

-- Eduardo Baitello
Source: StackOverflow