Search code examples
kuberneteskubectlkubernetes-jobs

Tell when Job is Complete


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?


Solution

  • 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