> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cleanup Label

> Explains Kyverno's per resource cleanup TTL label for automatic deletion, supported TTL formats, RBAC needs, reconciliation timing, and when to use label versus cluster cleanup policies.

When you need ongoing cluster housekeeping, scheduled, rule-based cleanup policies are ideal. But for resources that are known to be temporary at creation time — for example, a debug Pod, a short-lived namespace for a CI job, or a one-off test resource — Kyverno provides a simple, per-resource mechanism: the reserved label `cleanup.kyverno.io/ttl`.

How it works

* Add the `cleanup.kyverno.io/ttl` label to a resource's metadata at creation time.
* The Kyverno Cleanup Controller watches for that label, records the resource and its expiration, and deletes the resource when the TTL has passed.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/kyverno-cleanup-ttl-label-process.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=5fce5aba361ed2fde7e195e48d9cff7a" alt="The image illustrates the process of using the cleanup.kyverno.io/ttl label on Kubernetes resources, explaining how Kyverno handles cleanup by identifying the label, calculating expiration time, and deleting the resource when time is up." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/kyverno-cleanup-ttl-label-process.jpg" />
</Frame>

No policy required

Important: you do not need a cleanup policy for this to work. The presence of the `cleanup.kyverno.io/ttl` label on the resource itself is the instruction — the label triggers the Cleanup Controller to act.

TTL value formats

Kyverno supports two TTL value formats:

| Format             | Description                                                                                                                     | Examples                 |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
| Relative duration  | A duration relative to the moment Kyverno first sees the label. Uses standard duration units (s, m, h).                         | `30s`, `2m`, `1h`, `24h` |
| Absolute timestamp | An exact UTC deletion time using ISO 8601 / RFC 3339 format. Deletion occurs at that UTC timestamp regardless of creation time. | `2026-07-15T15:04:05Z`   |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/kyverno-ttl-value-formats-diagram.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=c3c7fdd78509c0b0a7ce184d99f18953" alt="The image explains two supported TTL value formats in Kyverno: &#x22;Relative Duration,&#x22; which specifies a time duration from when the label is seen, and &#x22;Absolute Timestamp (ISO 8601),&#x22; which specifies a specific UTC date and time for resource deletion." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/kyverno-ttl-value-formats-diagram.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Choose a relative duration when you want the countdown to start at creation time. Use an ISO 8601 timestamp when you require deletion at a precise UTC moment.
</Callout>

Practical example

A developer needs a temporary Pod to debug an issue and wants to ensure it is cleaned up automatically. Add the TTL label to the Pod manifest:

```yaml theme={null}
apiVersion: v1
kind: Pod
metadata:
  name: temp-debug-pod
  labels:
    # The magic label!
    cleanup.kyverno.io/ttl: 2m
spec:
  containers:
    - name: debug-tools
      image: busybox:1.35
      args:
        - sleep
        - "1d" # The container will run longer, but Kyverno will delete the Pod per TTL
```

When created, the Cleanup Controller records the resource and schedules deletion after two minutes. The container’s internal runtime does not prevent Kyverno from deleting the Pod when the TTL expires.

Permissions and RBAC

The TTL label is a trigger; the Cleanup Controller performs the actual deletion. Therefore, the controller must have the appropriate RBAC permissions to delete the resource type you label.

* Label a Pod for deletion → the controller must have `delete` permission on `pods`.
* Label a Deployment for deletion → the controller must have `delete` permission on `deployments`.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/permissions-ttl-labels-controller-reminder.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=7aab26646264dc4b984d6fbe4fa103d6" alt="The image is a reminder about permissions for labeling in a system. It explains that when using a TTL label, the controller requires permission to delete Pods or Deployments." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/permissions-ttl-labels-controller-reminder.jpg" />
</Frame>

<Callout icon="warning" color="#FF6B6B">
  Ensure the Kyverno Cleanup Controller's ClusterRole (or aggregated role) includes the `delete` verb for every resource type you want TTL-based cleanup to manage. Missing delete permission prevents Kyverno from removing labeled resources.
</Callout>

The permission model is unified: the same aggregated ClusterRole that grants delete permissions for cleanup policies also covers TTL-based deletions. Grant the appropriate permissions once and both mechanisms will work.

Reconciliation and timing guarantees

A TTL like 90 seconds is respected, but deletion may not occur at the exact second the TTL expires. For efficiency, the Cleanup Controller reconciles periodically rather than continuously scanning all labeled resources.

Example timeline:

* Controller runs at 1 minute — sees the Pod but not expired.
* TTL expires at 90 seconds — controller is not running at that exact moment.
* Next controller run (e.g., 2 minutes) — controller detects the expired Pod and deletes it.

This periodic schedule is called the reconciliation interval and is configurable on the controller (default: `1m`).

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/fine-tuning-reconciliation-interval-ttl.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=cb0c868583a8f5e7dede88bab596351b" alt="The image is titled &#x22;Fine-Tuning: The Reconciliation Interval&#x22; and features a question about TTL deletion timing, with an answer explaining that the Cleanup Controller runs on a schedule, not checking every second." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/fine-tuning-reconciliation-interval-ttl.jpg" />
</Frame>

You can adjust the controller behavior with the `--ttlReconciliationInterval` flag (or corresponding configuration), for example:

```text theme={null}
--ttlReconciliationInterval=30s
```

Smaller intervals yield closer-to-exact deletion timing at the cost of more frequent controller reconciliation.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/reconciliation-interval-kyverno-ttl-detail.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=1155da5206719ec474a74e30e85d9e36" alt="The image provides technical details about the &#x22;Reconciliation Interval,&#x22; including its configuration using the --ttlReconciliationInterval flag in the Kyverno cleanup controller, and states that the default value is 1 minute." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/reconciliation-interval-kyverno-ttl-detail.jpg" />
</Frame>

When to use each cleanup method

Use the method that best fits your workflow:

| Method                         | Trigger                                                         | Who typically applies it                               | Best use cases                                                                                                  |
| ------------------------------ | --------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| Cleanup policies               | Policy rules that find and delete resources (labels, age, etc.) | Cluster administrators                                 | Broad, ongoing housekeeping; discovering stale resources across namespaces                                      |
| `cleanup.kyverno.io/ttl` label | Per-resource label indicating deletion time/duration            | Developers or automation (CI/CD) creating the resource | Per-resource, self-contained expiration behavior; temporary debug Pods, ephemeral test namespaces, CI artifacts |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/D-p9N2q-xD7686Bp/images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/cleanup-policy-vs-ttl-label-comparison.jpg?fit=max&auto=format&n=D-p9N2q-xD7686Bp&q=85&s=e57fac33e04843022819bc2d18fea2a7" alt="The image is a comparison table outlining when to use the methods &#x22;CleanupPolicy&#x22; and &#x22;cleanup.kyverno.io/ttl Label,&#x22; detailing aspects such as how each works, triggers, who defines them, and best use cases." width="1920" height="1080" data-path="images/Prep-Course-Kyverno-Certified-Associate-KCA-Certification/Cleanup-Policies/Cleanup-Label/cleanup-policy-vs-ttl-label-comparison.jpg" />
</Frame>

Summary

* Use cleanup policies for administrator-defined, rule-driven housekeeping across the cluster.
* Use `cleanup.kyverno.io/ttl` for per-resource, explicit expiration when resources are known to be temporary at creation time.

Further reading and references

* Kyverno Cleanup Controller (docs): [https://kyverno.io/docs](https://kyverno.io/docs)
* ISO 8601 / RFC 3339 timestamps: [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt)
* Kubernetes RBAC documentation: [https://kubernetes.io/docs/reference/access-authn-authz/rbac/](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/kyverno-certified-associate/module/38c696a0-131e-44d4-9265-2e8b3c6abe20/lesson/06aa49c9-fc2f-4f26-9e16-d0c557f8fb9a" />
</CardGroup>
