kubernetes - 持久卷 - Kubernetes :无法删除PersistentVolumeClaim pvc

通过调用,我创建了以下持久卷

kubectl create -f nameOfTheFileContainingTheFollowingContent.yaml


apiVersion: v1


kind: PersistentVolume


metadata:


 name: pv-monitoring-static-content


spec:


 capacity:


 storage: 100Mi


 accessModes:


 - ReadWriteOnce


 hostPath:


 path:"/some/path"



---



apiVersion: v1


kind: PersistentVolumeClaim


metadata:


 name: pv-monitoring-static-content-claim


spec:


 accessModes:


 - ReadWriteOnce


 storageClassName:""


 resources:


 requests:


 storage: 100Mi



在这之后我尝试删除pvc 。 但这个命令在调用时卡住了,kubectl describe pvc pv-monitoring-static-content-claim 我得到以下结果


Name: pv-monitoring-static-content-claim


Namespace: default


StorageClass:


Status: Terminating (lasts 5m)


Volume: pv-monitoring-static-content


Labels: <none>


Annotations: pv.kubernetes.io/bind-completed=yes


 pv.kubernetes.io/bound-by-controller=yes


Finalizers: [foregroundDeletion]


Capacity: 100Mi


Access Modes: RWO


Events: <none>



还有 kubectl describe pv pv-monitoring-static-content


Name: pv-monitoring-static-content


Labels: <none>


Annotations: pv.kubernetes.io/bound-by-controller=yes


Finalizers: [kubernetes.io/pv-protection foregroundDeletion]


StorageClass:


Status: Terminating (lasts 16m)


Claim: default/pv-monitoring-static-content-claim


Reclaim Policy: Retain


Access Modes: RWO


Capacity: 100Mi


Node Affinity: <none>


Message:


Source:


 Type: HostPath (bare host directory volume)


 Path: /some/path


 HostPathType:


Events: <none>



没有使用持久卷的pod运行。谁能告诉我为什么pvc和pv没有被删除?

时间:

在删除PVC之前,请先删除PV ,另外,删除任何正在声明任何引用的PVC的pod/部署,有关更多信息请查看使用中的存储对象保护

刚刚遇到这个问题。

我删除了使用此引用的部署,PV/PVCs自动终止。

在我的例子中,只要删除与pv和pvc相关联的,终止状态中的pv和pvc就会消失,

PV和PVC受保护。

你应该像这样运行这个命令来解决它


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



...