<p>I am running a kubernetes job on GKE and want to delete the job automatically after the job is completed.</p>

<p>Here is my configuration file for the job.
I set <code>ttlSecondsAfterFinished: 0</code> but the job was not deleted automatically.
Am I missing something?</p>

<ul>
<li>cluster / node version: 1.12.8-gke.10</li>
</ul>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  # automatically clean up finished job
  ttlSecondsAfterFinished: 0
  template:
    metadata:
      name: myjob
    spec:
      containers:
        - name: myjob
          image: gcr.io/GCP_PROJECT/myimage:COMMIT_SHA
          command: ["bash"]
          args: ["deploy.sh"]
      # Do not restart containers after they exit
      restartPolicy: Never
</code></pre>

Yohei Onishi
<p>It depends how did you create job. </p>

<p>If you are using CronJob you can use <code>spec.successfulJobsHistoryLimit</code> and <code>spec.failedJobsHistoryLimit</code> and set values to 0. It will say K8s to not sotre any previously finished jobs.</p>

<p>If you are creating pods using YAMLs you have to deleted it manually. However you can also set CronJob to execute command each 5 minutes.</p>

<pre><code>kubectl delete job $(kubectl get job -o=jsonpath='{.items[?(@.status.succeeded==1)].metadata.name}')
</code></pre>

<p>It will delete all jobs with status succeded.</p>
