Help Center/ Cloud Container Engine/ FAQs/ Storage/ Why Cannot I Delete a PV or PVC Using the kubectl delete Command?
Updated on 2024-07-04 GMT+08:00

Why Cannot I Delete a PV or PVC Using the kubectl delete Command?

Symptom

An existing PV or PVC cannot be deleted by running the kubectl delete command and it remains in the terminating state.

Possible Causes

To prevent data loss caused by mis-deletion of PVs or PVCs, Kubernetes provides a data protection mechanism. A PV or PVC cannot be directly deleted using the kubectl delete command.

Solution

Run the kubectl patch command first to remove the protection mechanism and then delete the PV or PVC.

If you have run kubectl delete to delete a PV or PVC, the PV or PVC remains in the terminating state. It will be directly deleted after you run the kubectl patch command.

  • Run the following command to delete a PV:
    kubectl patch pv <pv-name> -p '{"metadata":{"finalizers":null}}'
    kubectl delete pv <pv-name>
  • Run the following command to delete a PVC:
    kubectl patch pvc <pvc-name> -p '{"metadata":{"finalizers":null}}'
    kubectl delete pvc <pvc-name>