Devendra Bhatte
Devendra Bhatte

Reputation: 358

Is there a better way to wait for Kubernetes job completion?

I currently use the following script to wait for the job completion

ACTIVE=$(kubectl get jobs my-job -o jsonpath='{.status.active}') until [ -z $ACTIVE ]; do ACTIVE=$(kubectl get jobs my-job -o jsonpath='{.status.active}') ; sleep 30 ; done

The problem is the job can either fail or be successful as it is a test job.

Is there a better way to achieve the same?

Upvotes: 4

Views: 3675

Answers (1)

Michael Hausenblas
Michael Hausenblas

Reputation: 13941

Yes. As I pointed out in kubectl tip of the day: wait like a boss, you can use the kubectl wait command.

Upvotes: 1

Related Questions