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
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:
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
Post a Comment