<p>Pods in <code>error</code> state are not getting cleaned up.</p>
<p>I can manually remove these pods using:</p>
<pre><code>kubectl delete pod --field-selector status.phase=Failed
</code></pre>
<p>Is there any <code>annotation</code> or <code>label</code> that I can use for auto-cleanup? What's the recommended way to do this?</p>

Dev
<p>As per Kubernetes official doc on <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-garbage-collection" rel="nofollow noreferrer">Garbage collection of Pods</a>;</p>
<blockquote>
<p>The Pod garbage collector (PodGC), which is a controller in the
control plane, cleans up terminated Pods (with a phase of <code>Succeeded</code> or
<code>Failed</code>), when the number of Pods exceeds the configured threshold
(determined by <code>terminated-pod-gc-threshold</code> in the
<code>kube-controller-manager</code>). This avoids a resource leak as Pods are
created and terminated over time.</p>
</blockquote>
<p>Refer to a similar Github issue on <a href="https://github.com/kubernetes/kubernetes/issues/99986" rel="nofollow noreferrer">Auto-delete failed Pods #99986</a> for more details.</p>
<p><strong>Without Cronjob:</strong> To clean up the failed pods created by kubernetes job automatically without using cronjob, you can set a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#ttl-mechanism-for-finished-jobs" rel="nofollow noreferrer">TTL</a> on your <strong>Job</strong> to have the pods cleaned up automatically.</p>
<p><strong>With Cronjob:</strong>  <em>CleanUp Script</em> written by <strong>Chris Ed Rego’s Medium blog</strong> on <a href="https://chrisedrego.medium.com/how-to-automatically-clean-up-failed-kubernetes-pod-every-24-hours-d66ac2a3964d" rel="nofollow noreferrer">How to automatically clean up failed Kubernetes Pod every 24 hours</a>, which may help to resolve your issue.</p>
<p><strong>Conclusion :</strong> This may need a fundamental change in kubernetes. Seems you may need a github issue to discuss further on this issue.</p>
