简体   繁体   English

重新部署 kubernetes statefulset 是否保留持久卷声明?

[英]Does re-deploying kubernetes statefulset preserve persistent volume claim?

We have a kubernetes statefulset with a persistent volume claim for storage class "zookeeper"我们有一个 kubernetes statefulset,其中包含存储类“zookeeper”的持久卷声明

There are 6 persistent volumes of storage class "zookeeper"存储类“zookeeper”有6个持久卷

The deployment is done using a Helm chart.部署是使用 Helm 图表完成的。 When I first install the helm chart with 3 replica count, the statefulset uses say, Pv1,Pv2 and Pv3.当我第一次安装具有 3 个副本计数的舵图时,statefulset 使用 Pv1、Pv2 和 Pv3。 All running ok.一切运行正常。

Delete purge the helm chart.删除清除舵图。

Re-install the same Helm chart with same number of replicas, 3 This time will the statefulset chose the same Persistent volumes, Pv1, Pv2 and Pv3 or will it choose any random Pv's from the 6 Pv's.使用相同数量的副本重新安装相同的 Helm chart,3 这次 statefulset 将选择相同的 Persistent 卷,Pv1、Pv2 和 Pv3,或者它会从 6 个 Pv 中选择任何随机 Pv。 This is important because across deployments, if the persistent volume changes, the zookeeper "myid" is messed-up.这很重要,因为跨部署,如果持久卷发生变化,zookeeper“myid”就会搞砸。

StatefulSet provides a key named as volumeClaimTemplates using that, you can request the PVC from the storage class dynamically. StatefulSet 提供了一个名为volumeClaimTemplates的密钥,您可以使用它动态地从存储类请求 PVC。 The volumeClaimTemplates will provide stable storage using PersistentVolumes provisioned by a PersistentVolume Provisioner. volumeClaimTemplates将使用 PersistentVolume Provisioner 提供的 PersistentVolumes 提供稳定的存储。

volumeClaimTemplates:
- metadata:
    name: my-pv
  spec:
    accessModes: 
      - ReadWriteMany
    resources:
      requests:
        storage: 1Gi

When you have multiple replica, you will see the pods are created one by one sequentially, and the PVC is requested during the pod creation.The PVC naming is combination of volumeClaimTemplate name + pod-name + order number .当你有多个replica时,你会看到pod是一个一个依次创建的,在pod创建的时候会请求volumeClaimTemplate name + pod-name + order number命名是volumeClaimTemplate name + pod-name + order number

For example, we will have the following PVCs naming例如,我们将有以下 PVC 命名

my-pv-app-0
my-pv-app-1
.. and so on

The volume is mount to the respective pod in order there after any restart by scaling operation on StatefulSet will not delete the volumes associated with the StatefulSet.卷被挂载到相应的 pod,以便在通过对 StatefulSet 的缩放操作重新启动后,不会删除与 StatefulSet 关联的卷。

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

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