<p>We have a kubernetes statefulset with a persistent volume claim for storage class "zookeeper"</p>

<p>There are 6 persistent volumes of storage class "zookeeper"</p>

<p>The deployment is done using a Helm chart. When I first install the helm chart with 3 replica count, the statefulset uses say, Pv1,Pv2 and Pv3. All running ok.</p>

<p>Delete purge the helm chart.</p>

<p>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.
This is important because across deployments, if the persistent volume changes, the zookeeper "myid" is messed-up.</p>

Sameer Mene
<p>StatefulSet provides a key named as <code>volumeClaimTemplates</code> using that, you can request the PVC from the storage class dynamically. The <code>volumeClaimTemplates</code> will provide stable storage using PersistentVolumes provisioned by a PersistentVolume Provisioner.</p>

<pre><code>volumeClaimTemplates:
- metadata:
    name: my-pv
  spec:
    accessModes: 
      - ReadWriteMany
    resources:
      requests:
        storage: 1Gi
</code></pre>

<p>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  <code>volumeClaimTemplate name + pod-name + order number</code>. </p>

<p>For example, we will have the following PVCs naming</p>

<pre><code>my-pv-app-0
my-pv-app-1
.. and so on
</code></pre>

<p>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. </p>
