Skip to main content
This lesson demonstrates how a finalizer ensures external cleanup is completed before a custom WebApp resource is fully removed from a Kubernetes cluster. The environment for this exercise is already prepared — files and cluster state are in place. Focus on the command outputs and the Kubernetes behavior that illustrate how finalizers protect external resources. Prerequisites
  • A Kubernetes cluster with the WebApp custom resource and a controller that implements a finalizer-based external cleanup.
  • Namespace: webapp-demo (for the WebApp CR) and webapp-external (for the external ConfigMap).
Steps
  1. Confirm the WebApp custom resource exists and inspect its finalizers.
The JSONPath output shows the finalizer webapp.kodekloud.com/finalizer attached to the WebApp resource. This finalizer prevents the API server from permanently removing the object until the controller performing external cleanup removes the finalizer.
  1. Confirm the external ConfigMap exists and has no owner references.
The second command returns an empty line, indicating there are no ownerReferences set on the external ConfigMap. Because the external resource is not owned by the WebApp object, it requires explicit external cleanup by the controller (which is coordinated via the finalizer).
Finalizers are used when deleting a Kubernetes object requires external cleanup steps (for example, deleting resources in another namespace or cleaning up entries in an external system). The finalizer blocks the API server from completing deletion until the controller performs the cleanup and removes the finalizer.
  1. Delete the WebApp resource and observe the result.
When you issue this delete, the API server marks the WebApp with a deletion timestamp but will not remove the resource until the finalizer is cleared. The controller should detect the pending deletion, perform external cleanup (delete the external ConfigMap in webapp-external), then remove the finalizer so the API server can complete the deletion.
  1. Verify that both the WebApp resource and the external ConfigMap are gone.
Both resources are now absent. This confirms the finalizer protected the WebApp resource from being fully deleted until the external cleanup (removal of the external ConfigMap) was completed by the controller. Summary Links and references This exercise illustrates the pattern where a finalizer coordinates a controller-driven cleanup of external resources before the API server completes deletion of a Kubernetes object.

Watch Video