Kubernetes: Can't delete PersistentVolumeClaim (pvc)

后端 未结 9 1737
無奈伤痛
無奈伤痛 2020-12-13 02:08

I created the following persistent volume by calling

kubectl create -f nameOfTheFileContainingTheFollowingContent.yaml

apiVersion: v1
ki         


        
相关标签:
9条回答
  • 2020-12-13 02:23

    For me pv was in retain state, hence doing the above steps did not work.

    1st we need to change policy state as below :

    kubectl patch pv PV_NAME -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
    

    Then delete pvc as below.

    kubectl get pvc
    
    kubectl delete pvc PVC_NAME
    

    finally, delete pv with

    kubectl delete pv PV_NAME
    
    0 讨论(0)
  • 2020-12-13 02:27

    This happens when persistent volume is protected. You should be able to cross verify this:

    Command:

    kubectl describe pvc PVC_NAME | grep Finalizers

    Output:

    Finalizers: [kubernetes.io/pvc-protection]

    You can fix this by setting finalizers to null using kubectl patch:

    kubectl patch pvc PVC_NAME -p '{"metadata":{"finalizers": []}}' --type=merge
    

    Ref; Storage Object in Use Protection

    0 讨论(0)
  • 2020-12-13 02:27

    Just met this issue hours ago.

    I deleted deployments that used this references and the PV/PVCs are automatically terminated.

    0 讨论(0)
  • 2020-12-13 02:30

    In my case, as long as I delete the pod associated to both pv and pvc, the pv and pvc in terminating status are gone

    0 讨论(0)
  • 2020-12-13 02:33

    I'm not sure why this happened, but after deleting the finalizers of the pv and the pvc via the kubernetes dashboard, both were deleted. This happened again after repeating the steps I described in my question. Seems like a bug.

    0 讨论(0)
  • 2020-12-13 02:33

    You can get rid of editing your pvc! Remove pvc protection.

    1. kubectl edit pvc YOUR_PVC -n NAME_SPACE
    2. Manually edit and put # before this line
    3. All pv and pvc will be deleted
    0 讨论(0)
提交回复
热议问题