简体   繁体   English

如何从 GKE 中的持久卷中删除数据?

[英]How to delete data from a persistent volume in GKE?

I am trying to delete the data in a pv so that I can use a fresh data storage.我正在尝试删除 pv 中的数据,以便我可以使用新的数据存储。

I've tried both kubectl delete pvc datastorage and kubectl delete pv datastorage - they removed the pv from my pod, but it was then attached again.我已经尝试过kubectl delete pvc datastoragekubectl delete pv datastorage - 他们从我的 pod 中删除了 pv,但随后又重新附加了它。

I'm using GKE, and I've also tried to delete the Storage from the console directly.我正在使用 GKE,我也尝试直接从控制台中删除存储。 However, my data is still there, and reflected within the running pods.但是,我的数据仍然存在,并反映在正在运行的 pod 中。

How do I delete the data from the storage?如何从存储中删除数据?

If your pod is part of a deployment or statefulset, delete it and on recreation you will get a new pvc.如果您的 pod 是部署或 statefulset 的一部分,请将其删除,然后在重新创建时您将获得一个新的 pvc。

Use the following使用以下

    kubectl delete pods [name of pod]
    kubectl get pvc
    kubectl get pv
    

If a user deletes a PVC in active use by a Pod, the PVC is not removed immediately.如果用户删除 Pod 正在使用的 PVC,PVC 不会立即被删除。 PVC removal is postponed until the PVC is no longer actively used by any Pods. PVC 移除被推迟,直到 PVC 不再被任何 Pod 主动使用。 Also, if an admin deletes a PV that is bound to a PVC, the PV is not removed immediately.此外,如果管理员删除绑定到 PVC 的 PV,该 PV 不会立即删除。 PV removal is postponed until the PV is no longer bound to a PVC. PV 删除被推迟,直到 PV 不再绑定到 PVC。 For further information, please see Storage Object in Use Protection有关详细信息,请参阅使用保护中的存储 Object

Having said that, it will be best to approach deletion in this order:话虽如此,最好按以下顺序进行删除:

  1. kubectl delete pod --pod-name kubectl 删除 pod --pod-name
  2. kubectl delete pvc --pvc-name kubectl 删除 pvc --pvc-name
  3. kubectl delete pv --pv-name kubectl 删除 pv --pv-name

Another way is to edit your yaml file and set your Reclaim Policy to Delete, the deletion will remove both the PersistentVolume object from Kubernetes, as well as the associated storage asset in the external infrastructure.另一种方法是编辑您的 yaml 文件并将您的回收策略设置为删除,删除将从 Kubernetes 中删除 PersistentVolume object,以及相关的外部存储基础设施。 For reference see this documentation on Reclaiming .有关参考,请参阅有关Reclaiming的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM