I am trying to setup automation around my Kubernetes storage and hitting some problems. I thought I would ask if there is a solution for this in the community.
I’m working with csi-driver-nfs for manage storage on Kubernetes.
The two Kubernetes storage options I am seeing each have a limitation:
Dynamic Storage: In this way, after I created a PVC without spec VolumeName, driver also create a PV with random name like pvc-<random uuid>
and a folder has the same name in shared folder at nfs host then mount to it.
I can’t control the name of the Persistent Volume nor the directory that it creates on disk (making it hard to connect to again if needed). Somehow, I recreate the PVC and cannot bound to that PV again (because recreate PVC also create a new PV)
Static Storage: I have to manually create the folder in shared folder at nfs host then create a Persistent Volume then mount to it.
Both of these can be overcome with more work, so I thought I would ask:
Is there a way using dynamic storage (aka Storage Classes) to choose the Persistent Volume name (so it can be re-connected to) and folder name that is created?
OR
Is there a way to manually created Persistent Volume that also create the folder in shared folder of nfs host from given name in the yaml? (This is perferred.)
For more details about my idea, I have used a test yaml file bellow:
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
csi:
driver: nfs.csi.k8s.io
volumeAttributes:
server: 192.168.1.10
share: /mnt/nfs
subDir: nfs-pv # This is the directory in the shared folder on NFS server that I want it to create
volumeHandle: nfs-pv
mountOptions:
- nfsvers=4.1
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs-csi-retain
volumeMode: Filesystem
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: nfs-csi-retain
volumeMode: Filesystem
volumeName: nfs-pv
---
apiVersion: v1
kind: Pod
metadata:
name: myapp
labels:
name: myapp
spec:
containers:
- name: myapp
image: ubuntu:latest
command: ["sleep", "infinity"]
resources:
limits:
memory: "128Mi"
cpu: "500m"
volumeMounts:
- name: nfs-pv
mountPath: /mnt/nfs
volumes:
- name: nfs-pv
persistentVolumeClaim:
claimName: nfs-pvc
In above manifest, I spec volumeAttributes.subDir
and expect csi driver will create folder when I create Persistent Volume (but it didn’t). And pod stuck at ContainerCreating
, output when I describe pod is Output: mount.nfs: mounting 192.168.1.10:/mnt/nfs/nfs-pv failed, reason given by server: No such file or directory
So I think “it” knows where I want to mount, just there is no folder to mount.