Yan*_*lem 34 kubernetes persistent-volumes persistent-volume-claims
我通过调用创建了以下持久卷
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
Run Code Online (Sandbox Code Playgroud)
在此之后我试图删除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>
Run Code Online (Sandbox Code Playgroud)
并为 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>
Run Code Online (Sandbox Code Playgroud)
没有使用持久卷的pod运行.有人可以给我一个提示,为什么不删除pvc和pv?
小智 34
当持久卷受到保护时,会发生这种情况。您应该可以交叉验证:
命令:
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
Run Code Online (Sandbox Code Playgroud)
参考; 使用中的存储对象保护
Yan*_*lem 21
我不确定为什么会这样,但是在通过kubernetes仪表板删除pv和pvc的终结器之后,两者都被删除了.重复我在问题中描述的步骤后再次发生这种情况.好像是一个bug.
小智 10
对我来说 pv 处于保留状态,因此执行上述步骤不起作用。
第一,我们需要改变政策状态如下:
kubectl patch pv PV_NAME -p '{"spec":{"persistentVolumeReclaimPolicy":"Delete"}}'
Run Code Online (Sandbox Code Playgroud)
然后删除 pvc 如下。
kubectl get pvc
kubectl delete pvc PVC_NAME
Run Code Online (Sandbox Code Playgroud)
最后,删除 pv
kubectl delete pv PV_NAME
Run Code Online (Sandbox Code Playgroud)
如果PV仍然存在,则可能是因为将ReclaimPolicy设置为Retain,在这种情况下,即使PVC消失了也不会删除它。从文档:
持久卷可以具有各种回收策略,包括“保留”,“回收”和“删除”。对于动态配置的PersistentVolume,默认回收策略为“删除”。这意味着当用户删除相应的PersistentVolumeClaim时,将自动删除动态预配置的卷。如果卷中包含宝贵的数据,则这种自动行为可能是不合适的。在这种情况下,使用“保留”策略更为合适。使用“保留”策略,如果用户删除PersistentVolumeClaim,则不会删除相应的PersistentVolume。而是将其移至“发布”阶段,在该阶段可以手动恢复其所有数据
归档时间: |
|
查看次数: |
32903 次 |
最近记录: |