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.
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:
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