【K8S】k8s pv,pvc無法刪除問題

一般刪除步驟爲:先刪pod再刪pvc最後刪pv。

遇到的問題

但是遇到pv始終處於“Terminating”狀態,而且刪不掉。如下圖:

解決方法

直接刪除k8s中的記錄:

kubectl patch pv xxx -p '{"metadata":{"finalizers":null}}'

參考信息:

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

實例操作:

[root@binghe ~]# kubectl patch pvc test  -p '{"metadata":{"finalizers":null}}' -n k8s-test
persistentvolumeclaim/test patched
[root@binghe ~]# kubectl patch pvc datadir-zookeeper-zookeeper-0  -p '{"metadata":{"finalizers":null}}' -n k8s-test
persistentvolumeclaim/datadir-zookeeper-zookeeper-0 patched
[root@binghe ~]# kubectl patch pv d-bp1flc3jh6rcc0le0x7y  -p '{"metadata":{"finalizers":null}}' -n k8s-test 
persistentvolume/d-bp1flc3jh6rcc0le0x7y patched

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章