Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 388
russt Avatar asked Jun 21 '17 21:06

russt


People also ask

How do you use kubectl wait?

Use Wait command We utilize the 'wait' command to recess until the pods meet the requirements. Use kubectl apply to relate the variations to the cluster and wait a randomly set amount of time (60 seconds) to check the status of the pod. At this point, we expect the fresh deployment to be active and the old one removed.

What is kubectl rollout status?

The criteria for this are in the kubectl source. A deployment is "complete" if: It hasn't timed out. Its updated-replica count is at least its desired-replica count (every new pod has been created) Its current-replica count is at most its updated-replica count (every old pod has been destroyed)

How do I delete a job from Kubernetes?

Delete the job with kubectl (e.g. kubectl delete jobs/pi or kubectl delete -f ./job. yaml ). When you delete the job using kubectl , all the pods it created are deleted too.


1 Answers

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 
like image 115
abagshaw Avatar answered Sep 18 '22 19:09

abagshaw