Tell when Job is Complete

russt picture russt · Jun 21, 2017 · Viewed 27.3k times · Source

I'm looking for a way to tell (from within a script) when a Kubernetes Job has completed. I want to then get the logs out of the containers and perform cleanup.

What would be a good way to do this? Would the best way be to run kubectl describe job <job_name> and grep for 1 Succeeded or something of the sort?

Answer

abagshaw picture abagshaw · Jun 22, 2018

Since version 1.11, you can do:

kubectl wait --for=condition=complete job/myjob

and you can also set a timeout:

kubectl wait --for=condition=complete --timeout=30s job/myjob