If you’re running Kubernetes clusters, you might have encountered a persistent volume claim (PVC) that gets stuck in the terminating state. This can happen when some Kubernetes objects, such as Pods or StatefulSets, still rely on the PVC, and the Kubernetes control plane cannot remove it until those objects are deleted or updated.
To solve this problem, you can use the kubectl patch command with a specific flag to remove the finalizer from the PVC metadata. The finalizer is a field in the PVC’s metadata that signals the Kubernetes control plane to wait before deleting the PVC until some cleanup tasks are completed.
To remove the finalizer, you can run the following command:
kubectl patch pvc {PVC_NAME} -p '{"metadata":{"finalizers":null}}'
This command sends a patch request to the Kubernetes API server, which updates the PVC’s metadata by setting the finalizers field to null. This action allows the Kubernetes control plane to remove the PVC without waiting for any cleanup tasks.