How to replace dynamically provisioned PVCs for multi-replica StatefulSets

23 Views Asked by At

I have a Kubernetes cluster running on EKS. This cluster has a StatefulSet deployed to it with 3 replicas using dynamically provisioned PVCs from a manifest similar to below:

apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
...
spec:
  members: 3
  type: ReplicaSet
  statefulSet:
    spec:
      ...
      volumeClaimTemplates:
        - metadata:
            name: data-volume
          spec:
            resources:
              requests:
                storage: 512Gi

I would like to reassign the PVCs for each replica in the StatefulSet to test an approach to restoring a snapshot in the event of a disaster.

I understand volumes for StatefulSets can be set using the approach below (and reassigning a single PVC is fairly straightforward):

volumes:
  - name: mount
    persistentVolumeClaim:
      claimName: abc123-pvc

But, I don't know how to map dynamically created replicas back to existing PVCs. Is this possible?

1

There are 1 best solutions below

0
user5749218 On

Found the answer, you have to anticipate the names of the PVCs created for the replicas.

More details: https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/preexisting-pd