Search code examples
kuberneteslocal-storagekubernetes-podkubernetes-pvc

Persistent volume claims vs subPath


I would like to use a single mount point on a node (ie /data) and have a different sub folder for each PersistentVolumeClaim that I am going to use in my cluster.

At the moment I have multiple StorageClass and PersistentVolume for each sub folder, for example:

---
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: prometheus
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus
  labels:
    type: local
spec:
  storageClassName: prometheus
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/data/prometheus"
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: disk
              operator: In
              values:
                - local

As you can image having a StorageClass, a PersistentVolume for each PersistentVolumeClaim looks a bit of an overkill.

I have tried to use a single StorageClass and PersistentVolume (just pointing to /data), the usePath option (ie prometheus) with multiple PersistentVolumeClaim. But I have noticed that if the securityContext.fsGroupChangePolicy option is enabled it will apply the user/group changes to root of the volume (ie /data) not to the subPath (ie /data/prometheus).

Is there a better solution?

Thanks


Solution

  • local-path-provisioner seems to be a good solution.