K8s - Finalizer

 

Finalizers are conditions that must be satisfied before a resource can be deleted. When a delete is ordered on a finalized resource, the resource is locked in changes until the conditions are met.

Finalizers are used to signal to the control plane, or to custom controllers like Operators, to clean up for a resource before completely and finally removing it.

Some common finalizers you’ve likely encountered are:

  • kubernetes.io/pv-protection
  • kubernetes.io/pvc-protection
kubernetes.io/pv-protection, ensures that PVs are not removed while still bound to PVCs.

Similarly, the kubernetes.io/pvc-protection finalizer on PVCs blocks the deletion of a PVC that is still in use by a pod.

Let's try to implement finalizer on a pod. 

Below is my pod YAML:



Verifying the finalizer tag on my pod.



Let's trigger a delete call on the pod.



We can see the pod is in "Terminating" state.

What the pod log shows?


We see the kubelet has stopped the container, but the pod is in "Terminating" state. While it is in terminating state, let's remove the finalizer tag from the pod.


I have used $ kubectl patch command to remove the tag. And we can see the pod is deleted the moment we removed the finalizer tag.


Comments

Popular posts from this blog

K8s - ETCD

SRE/DevOps Syllabus

K8s - Deployment and HPA replicas