Kubernetes Cluster stuck on removing PV/PVC
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In the realm of container orchestration, Kubernetes stands out as a leading solution. While it offers robust management of containerized applications, users sometimes encounter difficulties, especially when dealing with persistent storage. A common issue faced by developers and system administrators is when Kubernetes clusters become stuck on removing Persistent Volumes (PV) or Persistent Volume Claims (PVC). Understanding the intricacies of these issues helps in resolving them efficiently.
Understanding PVs and PVCs in Kubernetes
Persistent Volumes (PV)
A Persistent Volume (PV) is a piece of storage in the cluster. Administrators provision these or they can be dynamically provisioned by storage classes. PVs are backed by physical storage like GCEPersistentDisk or AWSElasticBlockStore. Unlike regular storage, PVs have a lifecycle that is independent of the pod that uses them, which allows them to persist beyond the life of the pod.
Persistent Volume Claims (PVC)
A Persistent Volume Claim (PVC) is a request for storage by a user. Similar to how pods consume node resources, PVCs consume PV resources. A PVC specifies size, access modes, and optionally storage classes as well as labels.
The Problem: Kubernetes Stuck on Removing PV/PVC
While working with PVs and PVCs, issues can arise when trying to delete them. The common symptoms include:
- PVCs remaining in a Terminating state.
- PVs being stuck in a Released state.
Causes
Understanding the reasons behind these symptoms is key to resolving them:
- Finalizers Not Being RemovedPVCs and PVs use a mechanism called finalizers to ensure that certain cleanup operations are completed before the resource is fully deleted. If the finalizer is not removed due to failed cleanup operations, the resource remains stuck.
- Reclaim PolicyIf a PV has a reclaim policy set to
Retain, even after deleting the PVC, the PV remains, usually in aReleasedstate. This is by design, allowing administrators to manually handle data retention and cleanup. - Kubernetes Bugs or Version IssuesOccasionally, bugs in certain Kubernetes versions can cause deletion operations to be incomplete.
- Stuck ControllersInternal Kubernetes controllers responsible for managing the lifecycle of PVs and PVCs may become stuck, leading to pending deletions.
Troubleshooting and Resolution Techniques
To address these issues, a methodical approach is required:
1. Deleting Finalizers Manually
For PVCs stuck in a terminating state because of finalizers, consider manually editing the PVC resource to remove the finalizers. Use the following command:
Locate the finalizers field and remove the entries. Save the changes to allow the PVC to complete termination.
2. Handling Reclaim Policies
For PVs stuck in a Released state due to a Retain policy, ensure to:
- Manually intervene to clean up underlying storage resources.
- Change the reclaim policy to
Deleteif automatic cleanup is desired.
3. Fixing Stuck Controllers
Inspect logs for the controllers managing PV and PVC lifecycles. Ensure that there are no networking or configuration issues preventing these controllers from working properly.
4. Update or Patch Kubernetes
Ensure that your Kubernetes cluster is updated to the latest stable version where known issues are fixed. Regular updates and patches often resolve persistent issues with resource management.
Key Points Summary
Here is a summary table of the main points regarding issues and resolutions for Kubernetes PV/PVC deletion:
| Problem | Symptom | Possible Cause | Resolution |
| Finalizers Not Removed | PVC stuck in Terminating state | Cleanup operations not completed | Manually remove finalizers using kubectl edit pvc <pvc-name>. |
Retain Reclaim Policy | PV stuck in Released state | Manual cleanup needed | Change reclaim policy to Delete with kubectl patch. |
| Kubernetes Bugs or Version | Varied | Obsolete or buggy release | Update Kubernetes to the latest stable version. |
| Stuck Controllers | Pending deletion | Networking or configuration | Review controller logs, ensure connectivity, and correct configuration issues. |
Conclusion
Addressing issues around stuck PV/PVC deletions in Kubernetes involves understanding the lifecycle and reclaim policies of your storage resources. By following systematic troubleshooting steps, many of these problems can be resolved effectively, ensuring smooth operations of storage resources in Kubernetes environments. Keeping the Kubernetes cluster up to date and regularly monitoring for potential issues will further aid in mitigating these challenges.
Related reading
- Kubernetes CNI vs Kube-proxy
- kubernetes config map data value externalisation
- Kubernetes config on code repo vs on helm charts repo
- kubernetes configmap set from-file in yaml configuration
- Kubernetes ConfigMaps Volume Mount issue
- Kubernetes CoreDNS resolving names intermittently
- kubernetes configmaps for binary file
- Kubernetes CoreOS Ceph RBD

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.