Kubernetes ttlSecondsAfterFinished - automatically delete finished Jobs and their Pods
Answer: To clean up finished Jobs automatically, specify the ttlSecondsAfterFinished field of a Job. Once the TTL has expired, the Job is removed along with its dependent objects.
Example
apiVersion: batch/v1
kind: Job
metadata:
name: pi-with-ttl
spec:
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: pi
image: perl:5.34.0
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
kubectl patch job old-job --type=merge -p '{"spec":{"ttlSecondsAfterFinished":0}}'
How it works
- The TTL-after-finished controller is only supported for Jobs.
- The timer starts once the Job's status condition shows
CompleteorFailed; after the TTL expires, the Job becomes eligible for cascading removal. - Cleanup deletes the Job together with its dependent objects, and Kubernetes still honors lifecycle guarantees such as waiting for finalizers.
- Keeping a finished Job for a while is useful so you can tell whether it succeeded or failed.
Ways to set it
- In the Job manifest, so cleanup happens some time after it finishes.
- On existing, already finished Jobs, so they become eligible for cleanup.
- With a mutating admission webhook at creation time, so cluster administrators can enforce a TTL policy.
- With your own controller for Jobs that match a selector.
Caveats
- You can change the TTL after the Job is created or has finished, but if you extend it after the old period expired, Kubernetes doesn't guarantee to retain that Job.
- The controller compares timestamps stored in the Job, so time skew in your cluster may clean up Jobs at the wrong time.
See also
Claims
- id: C1 claim: The TTL controller only supports Jobs. source: S2 evidence: "The TTL-after-finished controller is only supported for Jobs."
- id: C2 claim: TTL cleanup deletes dependent objects too. source: S2 evidence: "it will delete its dependent objects together with it."
- id: C3 claim: The feature is sensitive to time skew. source: S1 evidence: "this feature is sensitive to time skew in your cluster"
Sources
- [S1] Automatic Cleanup for Finished Jobs. Kubernetes docs. https://kubernetes.io/docs/concepts/workloads/controllers/ttlafterfinished/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] ttlafterfinished.md (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/controllers/ttlafterfinished.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Automatic Cleanup for Finished Jobs; kubernetes/website (GitHub), ttlafterfinished.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Automatic Cleanup for Finished Jobs; kubernetes/website (GitHub), ttlafterfinished.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "Kubernetes ttlSecondsAfterFinished - automatically delete finished Jobs and their Pods." iinventedlight Library, iil:note:pm9zerxm, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-ttl-after-finished/. License: CC-BY-4.0.
@misc{iil_note_pm9zerxm,
author = {{iinventedlight}},
title = {{Kubernetes ttlSecondsAfterFinished - automatically delete finished Jobs and their Pods}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-ttl-after-finished/},
note = {Permanent ID iil:note:pm9zerxm. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-ttl-after-finished.md.