2

I'm trying to figure out how I can use a single nfs share with k8s persistent volume claims.

For example, let's say I have a single nfs pv configured:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs-storage
  nfs:
    path: /var/nfs_exports
    server: 10.9.0.205
    readOnly: false

Is it possible to create multiple volume claims that map to subdirectories within this single share?

For example again, let's say I create the following volume claims:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: influx-data
  namespace: kube-system
spec:
  storageClassName: nfs-storage
  accessModes:
  - ReadWriteMany
  resources:
     requests:
       storage: 5Gi
---

and:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: elasticsearch-data
  namespace: kube-system
spec:
  storageClassName: nfs-storage
  accessModes:
  - ReadWriteMany
  resources:
     requests:
       storage: 2Gi
---

I guess, that both claims will be bound to the pv, but there is no way to seperate the data of both elasticsearch and influxdb.

I hope you understand what I'm trying to do here (sorry, I find it difficult to explain). I just want to use a single nfs share that can be used by multiple pods, while still keeping their data seperate.

0

In this case (sharing one PV using two PVCs in two different folders ), you may use the subPath option in the configuration of the volumeMounts of your containers:

[...]
'spec': {
  'template': {
    'metadata': {'name': 'container_name'},
      'spec': {
        'restartPolicy': 'Never',
        'containers':[{
          'image': 'busybox',
          'name': 'example',
          'command': ['/bin/ash'],
          'args': ['-c', ls -l /data],
          'volumeMounts': [{
            'name': 'influx-vol-mount',
            'mountPath': '/data',
            'subPath': 'subpath_1',
            'readOnly': False
         },
         { 'name': 'es-vol-mount',
            'mountPath': '/data',
            'subPath': 'subpath_2',
            'readOnly': False
      }]
  }],
  'volumes': [
    {
    'name': 'influx-vol-mount',
    'persistentVolumeClaim': {'claimName': 'influx-data'}
    }, 
    {
    'name': 'store-vol',
    'persistentVolumeClaim': {'claimName': 'elasticsearch-data'}
    }
  ]
}
[...]
  • Thanks, but it doesn't work. Since there is only one PV, only one PVC can get bound to it, to other one remains in 'pending' state. I'm going to try to mount the PV in the pods directly, maybe that will work. – Jeroen Jacobs Dec 23 '17 at 10:26
  • I'm also considering mounting the nfs share on host-level instead of a pv, and using just hostPath within kubernetes and let it point to the nfs mount-point. – Jeroen Jacobs Dec 23 '17 at 10:32
0

I have read that a PV is bound one to one to a PVC and thus cannot be reused, but the PVC can be reused. See the following resources:

https://stackoverflow.com/questions/44204223/kubernetes-nfs-persistent-volumes-multiple-claims-on-same-volume-claim-stuck

https://docs.openshift.org/latest/install_config/storage_examples/shared_storage.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.