<p>How to delete the failed jobs in the kubernetes cluster using a cron job in gke?. when i tried to delete the failed jobs using following YAML, it has deleted all the jobs (including running)</p>
<pre><code>
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: XXX
namespace: XXX
spec:
schedule: &quot;*/30 * * * *&quot;
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 1
jobTemplate:
 spec:
   template:
     spec:
       serviceAccountName: XXX
       containers:
       - name: kubectl-runner
         image: bitnami/kubectl:latest
         command: [&quot;sh&quot;, &quot;-c&quot;, &quot;kubectl delete jobs $(kubectl get jobs | awk '$2 ~ 1/1' | awk '{print $1}')&quot;]
       restartPolicy: OnFailure
</code></pre>

<p>This one visually looks better for me:</p>
<pre><code>kubectl delete job --field-selector=status.phase==Failed
</code></pre>
