1. 程式人生 > 其它 >k8s pv,pvc無法刪除問題

k8s pv,pvc無法刪除問題

技術標籤:kubernetes容器

k8s pv,pvc無法刪除問題
一般刪除步驟為:先刪pod再刪pvc最後刪pv

但是遇到pv始終處於“Terminating”狀態,而且delete不掉。如下圖:
在這裡插入圖片描述
解決方法:

直接刪除k8s中的記錄:

1

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

例項操作:

[[email protected] ~]# kubectl patch pvc test-01  -p '{"metadata":{"finalizers":null}}' -n xitu-test
persistentvolumeclaim/test-es01 patched [[email protected] ~]# kubectl patch pvc datadir-0 -p '{"metadata":{"finalizers":null}}' -n xitu-test persistentvolumeclaim/datadir-0 patched [[email protected] ~]# kubectl patch pv d-bp1flc3jh6rcc0le0x7y -p '{"metadata":{"finalizers":null}}' -n xitu-test
persistentvolume/d-bp1flc3jh6rcc0le0x7y patched