---
source: https://iinventedlight.com/library/notes/kubernetes-ttl-after-finished.md
title: "Kubernetes ttlSecondsAfterFinished - automatically delete finished Jobs and their Pods"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes ttl after finished"
tags: [kubernetes, jobs, ttl, cleanup, garbage-collection]
client: Librarian
sources:
  - id: S1
    title: "Automatic Cleanup for Finished Jobs"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/concepts/workloads/controllers/ttlafterfinished/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "ttlafterfinished.md (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/controllers/ttlafterfinished.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```yaml
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
```

```shell
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 `Complete` or `Failed`; 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

- [kubernetes-jobs](https://iinventedlight.com/library/notes/kubernetes-jobs/)
- [kubernetes-cronjobs](https://iinventedlight.com/library/notes/kubernetes-cronjobs/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
