StatefulSet vs Retain reclaim policy of a PersistentVolume

huangapple go评论59阅读模式
英文:

StatefulSet vs Retain reclaim policy of a PersistentVolume

问题

我有一个问题,为什么要在StatefulSet中使用Retain保留策略的持久卷?StatefulSet不够安全吗?

据我所知,当由于StatefulSet正在减少其副本计数或因为删除了StatefulSet而导致StatefulSet管理的副本消失时,PVC及其支持的卷将保留下来,并且必须手动删除。

英文:

I have a question, what is the reason to use the Retain reclaim policy of a PersistentVolume for StatefulSet. Is StatefulSet not secure enough ?

As far as I know, when a StatefulSet-managed replica disappears, either because the StatefulSet is reducing its replica count, or because its StatefulSet is deleted, the PVC and its backing volume remains and must be manually deleted.

答案1

得分: 3

无法直接从 StatefulSet 中设置 PersistentVolume 的 persistentVolumeReclaimPolicy:,而且您可能不希望将其更改为默认值。

回收策略 告诉 Kubernetes 在删除 PersistentVolume 时应如何处理实际存储。如果您设置 persistentVolumeReclaimPolicy: Retain,那么无论实际使用的存储是什么,比如 AWS EBS 卷,它都将被保留下来,您将需要负责清理它。这在需要创建引用某些现有外部存储的 PersistentVolume 时偶尔会有用,但通常不是您应该使用的选项。

PersistentVolumeClaim 没有这个选项。它是一个告诉 Kubernetes 您希望存在某些特定存储的对象,但不告诉存储实际位于何处或其物理属性是什么。StatefulSet 为 PersistentVolumeClaim 提供了一个模板,而不是底层的 PersistentVolumes,因此您无法在 StatefulSet 派生的卷上设置回收策略。

与 StatefulSet 关联的卷的一个重要属性是每个副本都有自己的卷,通过自己的 PVC。这意味着集群会动态创建 PVC,并且集群的持久卷提供程序会动态分配外部存储并创建 PV。这反过来意味着您几乎肯定不希望在这些卷上设置 persistentVolumeReclaimPolicy: Retain:当您运行 kubectl delete pvc 来清理存储时,该选项会保留动态创建的外部存储,并且您需要手动找到它并进行清理。默认的 Delete 值会在删除 PersistentVolume 时删除外部存储,这很可能是您希望发生的事情。

英文:

You can't directly set the PersistentVolume persistentVolumeReclaimPolicy: from a StatefulSet, and you probably don't want to change it from the default.

The reclaim policy tells Kubernetes what to do with the actual storage behind a PersistentVolume when it is deleted. If you set persistentVolumeReclaimPolicy: Retain then whatever actual storage was in use, such as an AWS EBS volume, will simply be left behind and you'll be responsible for cleaning it up. This is very occasionally useful if you need to create a PersistentVolume that refers to some existing external storage, but it's not an option you should usually need.

A PersistentVolumeClaim doesn't have this option. It is an object that tells Kubernetes that you'd like some specific storage to exist, but not where that storage actually is or what its physical properties are. A StatefulSet provides a template for a PersistentVolumeClaim, not the underlying PersistentVolumes, and so you can't set a reclaim policy on a StatefulSet-derived volume.

An important property of StatefulSet-associated volumes is that each replica has its own volume, via its own PVC. That means the cluster dynamically creates PVCs, and the cluster's persistent volume provisioner dynamically allocates external storage and creates PVs. In turn, this means you almost certainly don't want to set persistentVolumeReclaimPolicy: Retain on these volumes: when you do kubectl delete pvc to clean up the storage, that option would leave the dynamically-created external storage behind, and you'd need to find that and clean it up by hand. The default Delete value will delete the external storage when the PersistentVolume is deleted, which is most likely what you want to happen.

huangapple
  • 本文由 发表于 2023年6月1日 16:53:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定