0

I am trying to delete the data in a pv so that I can use a fresh data storage.

I've tried both kubectl delete pvc datastorage and kubectl delete pv datastorage - they removed the pv from my pod, but it was then attached again.

I'm using GKE, and I've also tried to delete the Storage from the console directly. However, my data is still there, and reflected within the running pods.

How do I delete the data from the storage?

fuzzi
  • 1,967
  • 9
  • 46
  • 90

3 Answers3

2

If your pod is part of a deployment or statefulset, delete it and on recreation you will get a new pvc.

Use the following

    kubectl delete pods [name of pod]
    kubectl get pvc
    kubectl get pv
    
dany L
  • 2,456
  • 6
  • 12
2

If a user deletes a PVC in active use by a Pod, the PVC is not removed immediately. PVC removal is postponed until the PVC is no longer actively used by any Pods. Also, if an admin deletes a PV that is bound to a PVC, the PV is not removed immediately. PV removal is postponed until the PV is no longer bound to a PVC. For further information, please see Storage Object in Use Protection

Having said that, it will be best to approach deletion in this order:

  1. kubectl delete pod --pod-name
  2. kubectl delete pvc --pvc-name
  3. kubectl delete pv --pv-name
James S
  • 1,181
  • 1
  • 7
0

Another way is to edit your yaml file and set your Reclaim Policy to Delete, the deletion will remove both the PersistentVolume object from Kubernetes, as well as the associated storage asset in the external infrastructure. For reference see this documentation on Reclaiming.

かいぜん
  • 327
  • 2
  • 9