2

Basically, I have a problem deleting my spoc-volume-spoc-ihm-kube-test PVC I tried with:

kubectl delete -f file.yml
kubectl delete PVC

but I get every time the same Terminating Status. Also, when I delete the PVC the console is stuck in the deleting process.

Capacity: 10Gi Storage Class: rook-cephfs Access Modes: RWX

Here is the status in my terminal:

kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE spoc-volume-spoc-ihm-kube-test Terminating pvc-- 10Gi RWX rook-cephfs 3d19h

Thank You for your answers, Stack Community :)

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
Fuzzby
  • 83
  • 1
  • 7
  • did you have a look at: https://stackoverflow.com/questions/51358856/kubernetes-cant-delete-persistentvolumeclaim-pvc?rq=1 ? – testfile Apr 19 '22 at 09:57
  • Can you describe the pvc? `kubectl describe pvc spoc-volume-spoc-ihm-kube-test` ? – Kamol Hasan Apr 19 '22 at 10:11
  • Hello Thank you for the correction, yes I saw that response too, I fixed the problem with my colleague, the problem was simple; as long as you keep other pods, which depends on that pvc at a running state, the pvc will never be deleted. That's a also, I think one of the principle of Kubernetes, as long as the pod communicate with the pvc, the pvc can not be deleted,. – Fuzzby Apr 19 '22 at 10:31
  • Thank's a lot @KamolHasan `kubectl describe pvc spoc-volume-spoc-ihm-kube-test` is a good way to describe the pod, I will use it next time. My app works perfectly in the cluster ! – Fuzzby Apr 19 '22 at 10:44

2 Answers2

9

You need to first check if the volume is attached to a resource using kubectl get volume attachment. If your volume is in the list, it means you have a resource i.e a pod or deployment that is attached to that volume. The reason why its not terminating is because the PVC and PV metadata finalizers are set to kubernetes.io/pv-protection.

Solution 1:

Delete the resources that are attached/using the volume i.e pods, deployments or statefulsets etc. After you delete the stuck PV and PVC will terminate.

Solution 2

If you are not sure where the volume is attached, you can delete/patch the PV and PVC metadata finalizers to null as follows:

a) Edit the PV and PVC and delete or set to null the finalizers in the metadata

kubectl edit pv {PV_NAME}
kubectl edit pvc {PVC_NAME}

b) Simply patch the PV and PVC as shown below:

kubectl patch pvc {PV_NAME} -p '{"metadata":{"finalizers":null}}'
kubectl patch pvc {PVC_NAME} -p '{"metadata":{"finalizers":null}}'

Hope it helps.

Ngatia Frankline
  • 2,897
  • 2
  • 20
  • 19
4

I fixed the problem by deleting the pods depending on that pvc

The status: TERMINATING disappeared

Fuzzby
  • 83
  • 1
  • 7