我通过调用创建了以下持久卷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?
最佳答案
当持久卷受到保护时会发生这种情况。您应该能够交叉验证这一点:
命令:kubectl describe pvc PVC_NAME | grep Finalizers
输出:Finalizers: [kubernetes.io/pvc-protection]
您可以通过使用 kubectl patch
将终结器设置为 null 来解决此问题:
kubectl patch pvc PVC_NAME -p '{"metadata":{"finalizers": []}}' --type=merge
引用; Storage Object in Use Protection
关于Kubernetes:无法删除 PersistentVolumeClaim (pvc),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51358856/