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.
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.
There is a new API that delete jobs after completion and all the dependent elements. The TTLAfterFinished.
You can define it in the .spec.ttlSecondsAfterFinished
property of your job. The cleanup will happen X
seconds after the job is completed or failed.
As of 16, March, 2019, this API is in alpha, with version 1.12 and can only be used with alpha features enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With