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

查看:60
本文介绍了Kubernetes:无法删除 PersistentVolumeClaim (pvc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created the following persistent volume by calling

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 描述 pvc PVC_NAME |grep 终结器

输出:

终结器:[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

参考;存储对象使用保护

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

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