?? Why PV (Persistent Volume) and PVC (Persistent Volume Claim) get stuck in terminating state due to Finalizers
In Kubernetes, Persistent Volumes (PVs) and Persistent Volume Claims (PVCs) sometimes get stuck in a terminating state, complicating resource management. This issue typically arises when a finalizer prevents the automatic deletion of a resource.
Finalizers are a mechanism in Kubernetes that allows controllers to implement graceful deletion of objects before they are removed from the system. They ensure that specific cleanup operations are performed on a resource before it's deleted.
A common finalizer,?kubernetes.io/pv-protection, ensures that PVs are not removed while still bound to PVCs. This finalizer protects the PV by ensuring that it is either unbound from the claim or the claim is deleted.
Similarly, the?kubernetes.io/pvc-protection?finalizer on PVCs blocks the deletion of a PVC that is still in use by a pod. This finalizer works to ensure that the PVC isn't deleted before the data stored on it has been copied or migrated.
While finalizers offer important protection mechanisms, they can sometimes cause PVs and PVCs to get stuck in a terminating state if:
In such cases, deleting the finalizer(s) manually, after confirming that all necessary cleanup revisions are viable and safe, can help resolve the terminating state issue. However, this action should be performed with caution to avoid any unintended consequences.
To remove a finalizer from a PVC, use the following command as an example:
kubectl patch pvc pv-claim-name -p '{"metadata":{"finalizers":null}}'
Understanding the role of finalizers in managing PVs and PVCs can help you better address issues related to resource termination.
Stay tuned for more DevOps Tips & Tricks!
Software Engineer at iRem
9 个月Same here, good solution. I like Kubernetes docs, they are so clear on this. Manifest allowed me to create pvc with name/ with slash at the end but it is stuck at delete because of it .... nice right?