deletionTimestamp and puts the object into a Terminating state while finalizers remain. Controllers reconcile against that visible terminating object and perform any necessary cleanup before the API server finally removes the object.


metadata.finalizers. For example:
deletionTimestamp. Controllers must reconcile that object and perform cleanup before removing their finalizer.
When finalizers are present, reconcile follows two clear paths:
- Normal path (no
deletionTimestamp): ensure resources (in-cluster and external) exist and that your controller’s finalizer is attached before creating anything that requires cleanup later. - Cleanup path (
deletionTimestampset): stop creating/updating normal children, perform cleanup of owned external resources, and remove only your controller’s finalizer when cleanup succeeds.

- Add your finalizer before creating external resources — don’t create external state without protecting deletion.
- Only remove your controller’s finalizer once your cleanup has completed successfully.
- Make cleanup idempotent: if it runs multiple times (controller retries/crashes), it should safely treat already-deleted resources as success.
- Record failures in Status, Events, or Logs so operators can diagnose why an object remains Terminating.

Best practices for finalizers and cleanup
- Use stable, namespaced finalizer names like
webapp.kodekloud.com/finalizerto show ownership and avoid collisions. - Each controller should only remove the finalizers it added.
- Ensure cleanup is idempotent and resilient to transient errors.
- Surface blocking errors via Status, Events, and Logs.
Force-removing finalizers bypasses cleanup. Use it only as a recovery or emergency action, and after documenting the consequences.
Always add your controller’s finalizer before creating external resources, and make cleanup idempotent so retries and crashes are safe.
deletionTimestamp, performs a simulated external cleanup, removes its finalizer upon success, and then allows Kubernetes to complete the deletion.
Links and references
- Kubernetes API Conventions: Finalizers
- Owner References and Garbage Collection
- Controller pattern: Finalizers and Cleanup