What is the best way to delete a Pod after a Kubernetes Job completes

I have a situation in which I run a Kubernetes Job and then want to delete the pod in which the Job's containers run when the job completes. The Kubernetes documentation says the it is the responsibility of the user to delete the pod.

However, my goal is to run a CPU intensive job by spinning up a big honking pod, let the job run, and then upon job completion, automagically nuke the pod. My thinking is that paying for an expensive, resource intensive pod is worth it when the revenue producing job runs. Once the job is over, the revenue stream ends and I need to cut the expense, hence nuking the pod.

I am thinking of having my code in the job container send a out a message upon program completion to a publisher that is picked up by a subscriber. The subscriber knows how to run the command, kubectl delete jobs/myContainer to nuke the pod.

But, maybe there is a better way. Thus, I ask.

Thanks in advance.

1 answer

  • answered 2017-12-06 13:12 Radek 'Goblin' Pieczonka

    Why would you need to delete the pod at all ? If the job completed successfully (exit code 0) then the pod will be completed, it will no longer use cpu/memory resurces, and should be garbage collected when needed.