how can i delete kubernetes's pvc

10/1/2019

i try delete pvc but i cant

kubectl get --all-namespaces pvc

NAMESPACE      NAME            STATUS        VOLUME         CAPACITY   ACCESS MODES   STORAGECLASS   AGE
test-logging   es-local-pvc1   Terminating   es-local-pv1   450Gi      RWO                           21d
-- Jokky
kubernetes

2 Answers

10/1/2019

kubectl delete pvc es-local-pvc1

if you see any problem, most likely that the pvc is protected from deletion.

  finalizers:
  - kubernetes.io/pvc-protection

you need to edit the pvc and verify that finalizers under metadata is set to null using the below patch.

kubectl patch pvc <pvc-name> -p '{"metadata":{"finalizers":null}}'

Then you should be able to delete the pvc

-- P Ekambaram
Source: StackOverflow

10/1/2019

First of all you should try kubectl delete pvc es-local-pvc1 -n test-logging

If it doesnt help, then I absolutely agree with solution provided by @PEkambaram. Sometimes you can resolve this issue only by patching pv and pvc finalizers.

You can list finalizers by

kubectl describe pvc PVC_NAME | grep Finalizers

and change by

kubectl patch pvc <pvc-name> -p '{"metadata":{"finalizers":null}}'

Btw,the same could happen with PV also, ans you can do the same:

kubectl patch pv PV-NAME -p ’{“metadata”:{“finalizers”:null}}’

Github PV is stuck at terminating after PVC is deleted post also can help in situation when you need to patch pod

kubectl patch pvc db-pv-claim -p '{"metadata":{"finalizers":null}}'
kubectl patch pod db-74755f6698-8td72 -p '{"metadata":{"finalizers":null}}'
-- VKR
Source: StackOverflow