<p>I have a cronjob which run once every midnight, however one day I deployed wrong version of it and consequently the pod it made went failed soon.</p>
<p>So.. the problem is when I delete the failed pod the cronjob immediately recreates it. How can I stop it? Well anyhow its image is already broken so however it recreates new pod again and again it'd go fail.</p>
<p>my question is &quot;How can I delete failed pod created by cronjob?&quot;</p>
<p>P.S. I'm using rancher but I'm not sure my problem is related to it.</p>

<p><code>my question is &quot;How can I delete failed pod created by cronjob?&quot;</code></p>
<p>You can use <code>ttlSecondsAfterFinished</code> to control how long you want to keep <strong>either Complete or Failed job</strong> in your cluster.</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  ...
spec:
  schedule: ...
  ...
  jobTemplate:
    spec:
      ttlSecondsAfterFinished: 43200 &lt;-- example 12 hrs. 0 to clean immediately.
      template:
      ...
</code></pre>
<p>Another thing to note this is a K8s v1.21 beta feature at the point of this writing.</p>
