Home > Software engineering >  k8s persistent volumes "groups"?
k8s persistent volumes "groups"?

Time:09-01

I have a statefulset with 2 persistent volumes on each replica . . . I need to keep "groups" of disks together, so that app-disk-0 & data-disk-0 will always be on a pod together, app-disk-1 & data-disk-1 will always be on a pod together, etc. Is this possible without manual intervention?

CodePudding user response:

You could add some labels to your volumeClaimTemplates.

Although whenever I see pods attaching multiple PVC, I would try to refactor those. You could usually have something like:

volumes:
- name: pv
  persistentVolumeClaim: xxx
containers:
- volumeMounts:
  - name: pv
    mountPath: /var/lib/xxx
    subPath: app-data
  - name: pv
    mountPath: /etc/xxx
    subPath: app-config

A single PVC could regroup several volumes, using subPaths.

CodePudding user response:

a statefulset with 2 persistent volumes on each replica . . . I need to keep "groups" of disks together, so that app-disk-0 & data-disk-0 will always be on a pod together

This way no manual intervention:

apiVersion: apps/v1
kind: StatefulSet
...
spec:
  ...
  volumeClaimTemplates:
  - metadata:
      name: app-disk
    spec:
      ...
  - metadata:
      name: data-disk
    spec:
      ...
  • Related