<p>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 <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#job-termination-and-cleanup" rel="noreferrer">Kubernetes documentation says</a> the it is the responsibility of the user to delete the pod.</p>

<p>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.</p>

<p>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, <code>kubectl delete jobs/myContainer</code> to nuke the pod.</p>

<p>But, maybe there is a better way. Thus, I ask.</p>

<p>Thanks in advance.</p>

<p>There is a new API that delete jobs after completion and all the dependent elements.
The <a href="https://kubernetes.io/docs/concepts/workloads/controllers/ttlafterfinished/" rel="nofollow noreferrer">TTLAfterFinished</a>.</p>

<p>You can define it in the <code>.spec.ttlSecondsAfterFinished</code> property of your job. The cleanup will happen <code>X</code> seconds after the job is completed or failed.</p>

<p>As of 16, March, 2019, this API is in alpha, with version 1.12 and can only be used with alpha features enabled.</p>
