StatefulSets 和 PersistentVolumes 如何在相同的可用性区域进行配置?

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

How are StatefulSets and PersistentVolumes provisioned in the same Availability Zone?

问题

StatefulSet如何确保PersistentVolume和Pod始终在相同的可用区中配置?我了解StatefulSet中的每个Pod都具有存储标识,并且每个Pod将记住它正在使用的PVC,但我很难找到官方文档来支持这一点。

英文:

How does a StatefulSet ensure that a PersistentVolume and Pod will always be provisioned in the same Availability Zone? I understand that each pod in a StatefulSet has a storage identity, and that each pod will remember the PVC it is using, but am struggling to find the official documentation to support this.

答案1

得分: 2

pod will remember the PVC it is using, but am struggling to find the
official documentation to support this

我认为这是您正在寻找的确切内容

You can set the .spec.volumeClaimTemplates which can provide stable
storage using PersistentVolumes provisioned by a PersistentVolume
Provisioner.

您可以设置 .spec.volumeClaimTemplates,它可以提供稳定的存储,使用由 PersistentVolume Provisioner 配置的 PersistentVolumes。

参考文档:https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#volume-claim-templates

一般流程如下

您有一个**StorageClass(由 csi 支持)列出的区域(zones),K8s 使用轮询(round robin)方式创建PV(持久卷)**

根据PVC(持久卷声明),pod 访问**卷(volume)**并安排到特定可用区域(AZ)

英文:

> pod will remember the PVC it is using, but am struggling to find the
> official documentation to support this

I think here is the exact line you are looking for

> You can set the .spec.volumeClaimTemplates which can provide stable
> storage using PersistentVolumes provisioned by a PersistentVolume
> Provisioner.

Ref doc : https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#volume-claim-templates

The general flow goes like

You have StorageClass(backed by csi) which list of zones K8s goes round robin to create the PV

Based on the PVC pod access the volume and schedule to AZ

答案2

得分: 1

在Kubernetes深层,卷驱动程序具有告诉集群有关Pod放置的约束的能力。

如果您在AWS/EKS上运行此操作,实际的节点可能是EC2实例,而默认的卷类型是EBS卷,必须附加到单个节点。因此,当创建Pod时,集群需要将EBS卷挂载到Node的EC2实例上,为此,EC2实例和EBS卷需要位于同一可用区(AZ)。

有一个地方可以看到这实际上是在容器存储接口规范中写出的。CreateVolume RPC返回大量数据,但其中的一部分是TopologyRequirement子对象。您可以在该对象的注释中看到CSI驱动程序如何指示卷存在的特定区域/AZ,因此目标节点也必须在同一区域/AZ中。

StatefulSets在这个空间中并不做任何特殊处理;它们只创建带有这些PVC作为卷挂载的PersistentVolumeClaims和Pods。它们允许集群分配底层的PersistentVolumes并解决相应的放置约束。

英文:

Deep inside Kubernetes, the volume driver has the ability to tell the cluster what constraints it has on the pod placement.

If you're running this in AWS/EKS, your actual nodes are probably EC2 instances and the default volume type is an EBS volume, that must be attached to a single node. So when a Pod is created, the cluster needs to mount the EBS volume on the Node's EC2 instance, and for that to happen the EC2 instance and the EBS volume need to be in the same AZ.

One place to see this actually written out is in the Container Storage Interface specification. The CreateVolume RPC returns a lot of data, but one part of this is a TopologyRequirement sub-object. You can see in that object's comments how the CSI driver can indicate a specific region/AZ in which the volume exists and so the target node must be too.

StatefulSets don't do anything special in this space; they just create PersistentVolumeClaims and Pods with those PVCs mounted as volumes. They let the cluster allocate the underlying PersistentVolumes and resolve the corresponding placement contraints.

huangapple
  • 本文由 发表于 2023年3月9日 13:01:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75680599.html
匿名

发表评论

匿名网友

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

确定