k8s不能删除pv,pvc

一般删除步骤为:先删pod再删pvc最后删pv

但是遇到pv始终处于“Terminating”状态,而且delete不掉。

[root@k8s-master ops]# kubectl get  pvc -n kube-ops
NAME     STATUS        VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
opspvc   Terminating   opspv    20Gi       RWX                           15m
[root@k8s-master ops]# kubectl get  pv | grep ops
opspv                                                                               20Gi       RWX            Delete           Terminating   kube-ops/opspvc                                                           15m
[root@k8s-master ops]#

解决方法:

直接删除k8s中的记录:

[root@k8s-master ops]# kubectl patch pv opspv -p '{"metadata":{"finalizers":null}}'
persistentvolume/opspv patched
[root@k8s-master ops]# kubectl get  pv | grep ops
[root@k8s-master ops]# kubectl get  pvc -n kube-ops
NAME     STATUS        VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
opspvc   Terminating   opspv    0                                        17m
[root@k8s-master ops]# kubectl delete pvc opspvc  -n kube-ops
persistentvolumeclaim "opspvc" deleted
^C
[root@k8s-master ops]# kubectl get  pvc -n kube-ops
NAME     STATUS        VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
opspvc   Terminating   opspv    0                                        17m
[root@k8s-master ops]#
[root@k8s-master ops]# kubectl patch pvc opspvc  -p '{"metadata":{"finalizers":null}}' -n kube-ops
persistentvolumeclaim/opspvc patched
[root@k8s-master ops]# kubectl get  pvc -n kube-ops
No resources found.
[root@k8s-master ops]#

你可能感兴趣的:(k8s不能删除pv,pvc)