Reputation: 11
We have a kubernetes statefulset with a persistent volume claim for storage class "zookeeper"
There are 6 persistent volumes of storage class "zookeeper"
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.
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. This is important because across deployments, if the persistent volume changes, the zookeeper "myid" is messed-up.
Upvotes: 1
Views: 925
Reputation: 3571
StatefulSet provides a key named as volumeClaimTemplates
using that, you can request the PVC from the storage class dynamically. The volumeClaimTemplates
will provide stable storage using PersistentVolumes provisioned by a PersistentVolume Provisioner.
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
.
For example, we will have the following PVCs naming
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.
Upvotes: 3