3

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

yellowhat
  • 429
  • 6
  • 17
  • Remember that Stack Overflow is specifically about programming questions; administration questions about specific filesystem setups on Kubernetes nodes might be better asked on a different Stack Exchange site like [sf] or [devops.se]. As an application developer I wouldn't expect you to need either of the objects you show here, the cluster will create the PersistentVolume automatically from the PersistentVolumeClaim. – David Maze Nov 07 '22 at 10:26

2 Answers2

0

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

That's exactly how dynamic storage provisioning works. Single storage class specified in PVC used by a pod will provision single PV for that PVC. There's nothing wrong with it. I'd suggest using it if you are ok with its default volume reclaim policy of delete.

rok
  • 9,403
  • 17
  • 70
  • 126
  • But my kubernetes cluster is self-hosted, it is not on the cloud. Could you have a dynamic storage provisioning not on the cloud? Thanks – yellowhat Nov 07 '22 at 12:26
  • of course you can, see my blog post about [Dynamic Provisioning of Kubernetes Storage](https://www.rokpoto.com/kubernetes-storage-dynamic-provisioning/). I used `minikube` and its default storage class for dynamic storage provisioning. But you can use any (non-cloud) storage class in your self-hosted Kubernetes cluster. What matters is what provisioner you use. – rok Nov 07 '22 at 13:01
  • Can you point me to an example? Thanks – yellowhat Nov 07 '22 at 13:03
  • edited my previous comment – rok Nov 07 '22 at 13:05
  • see also [nfs provisioner](https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner) and storage class example using it – rok Nov 07 '22 at 13:07
0

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

yellowhat
  • 429
  • 6
  • 17