1

I created a gp2 storageclass in my eks cluster. When I create a statefulset instance, it will automatically creates a volume in AWS's EBS.

I backed up the mounted volumes bound to statefulset by using AWS's Backup service. But after I restore the Recovery point, it just created a newly mounted volume with a different name. How do I bind this new volume to statefulset's pod?

I tried to edit pv/pvc yaml but failed.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
Rainbird
  • 21
  • 3

1 Answers1

0

If you are using the volumeClaimTemplates in your YAML definition. it will use the create unique replicas for stateful sets with postfix -0, -1.

If you have already created the new PVC you and mount it to statefulset simply as the normal way we do in deployment with volume.

Example

apiVersion: "apps/v1"
kind: StatefulSet
metadata:
  name: busybox
spec:
  serviceName: busybox
  replicas: 1
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
        - name: busybox-container 
          image: "busybox"
          imagePullPolicy: "IfNotPresent"
          volumeMounts: 
            - name: volume
              mountPath: /tmp
      volumes:
        - name: volume
          persistentVolumeClaim:
            claimName: already-volume-claim

if you have multiple replicas running and have multiple PVC to attach you can use the volumeClaimTemplates itself.

ref link : Using a pre-existing disk in a StatefulSet

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Thank you for the answer. But what we want is not to change the default statefulset configuration. First reduce the number of replicas. Then replace the original pvc with the restored volume. Finally re-increase the number of replicas and bound the new pod to the new restored pvc. Is this operation possible? – Rainbird Oct 31 '22 at 06:05
  • Yes you can use the template itself but make the name get the match of PVC to the template format with postfix. here is the ref link : https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/preexisting-pd#pv_to_statefulset – Harsh Manvar Oct 31 '22 at 06:11