How to delete persistent volumes in Kubernetes

8/7/2019

I am trying to delete persistent volumes on a Kubernetes cluster. I ran the following command:

kubectl delete pv pvc-08e65270-b7ce-11e9-ba0b-0a1e280502e2 pvc-08e87826-b7ce-11e9-ba0b-0a1e280502e2 pvc-08ea5f97-b7ce-11e9-ba0b-0a1e280502e2 pvc-08ec1cac-b7ce-11e9-ba0b-0a1e280502e2

However it showed:

persistentvolume "pvc-08e65270-b7ce-11e9-ba0b-0a1e280502e2" deleted
persistentvolume "pvc-08e87826-b7ce-11e9-ba0b-0a1e280502e2" deleted
persistentvolume "pvc-08ea5f97-b7ce-11e9-ba0b-0a1e280502e2" deleted
persistentvolume "pvc-08ec1cac-b7ce-11e9-ba0b-0a1e280502e2" deleted

But the command did not exit. So I CONTROL+C to force exit the command. After a few minutes, I ran:

kubectl get pv

And the status is Terminating, but the volumes don't appear to be deleting.

How can I delete these persistent volumes?

-- Justin
kubernetes
persistent-volumes

2 Answers

8/7/2019

It is not recommended to delete pv it should be handled by cloud provisioner. If you need to remove pv just delete pod bounded to claim and then pvc. After that cloud provisioner should also remove pv as well.

kubectl delete pvc --all 

It sometimes could take some time so be patient.

-- FL3SH
Source: StackOverflow

3/18/2020

Delete all the pods, which is using the pvc(you want to delete), then delete the PVC(PersistentVolumeClaim) & PV(PersistentVolume) in sequence.

Some thing like below(in sequence):

  1. kubectl delete pod --all / pod-name
  2. kubectl delete pvc --all / pvc-name
  3. kubectl delete pv --all / pv-name
-- Shreyas
Source: StackOverflow