Kubernetes:无法删除PersistentVolumeClaim(pvc) [英] Kubernetes: Can't delete PersistentVolumeClaim (pvc)

查看:1366
本文介绍了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时,我得到以下结果

After this I tried to delete the pvc. But this command stuck. when calling kubectl describe pvc pv-monitoring-static-content-claim I get the following result

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吗?

There is no pod running that uses the persistent volume. Could anybody give me a hint why the pvc and the pv are not deleted?

推荐答案

在保护持久卷时会发生这种情况.您应该能够对此进行交叉验证:

This happens when persistent volume is protected. You should be able to cross verify this:

命令:

kubectl describe pvc PVC_NAME | grep Finalizers

输出:

Finalizers: [kubernetes.io/pvc-protection]

您可以通过使用kubectl patch将终结器设置为null来解决此问题:

You can fix this by setting finalizers to null using kubectl patch:

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

Ref; 使用保护中的存储对象

这篇关于Kubernetes:无法删除PersistentVolumeClaim(pvc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆