There are a couple of ways to mount a NFS volume in a Kubernetes Pod. This will go over mounting a share from an NFS server on to a directory inside of a Kubernetes Pod and is probably most simplistic way to accomplish this. You will need a server already set up and running NFS and a kubernetes cluster.
For my server I have the following set up in my
To mount the above share, or any directory under it, into the Pod, we need to add a volumeMounts and volumes section to our Pod. This is an example deployment file accomplishing just that.
apiVersion: apps/v1 kind: Deployment metadata: name: busybox spec: selector: matchLabels: app: busybox replicas: 1 template: metadata: labels: app: busybox spec: containers: - name: busybox image: busybox volumeMounts: - name: files mountPath: /files args: - sleep - "999999" volumes: - name: files nfs: server: fileserver.domain.name path: /share/files
Also of note, the mountPath does not have to exist prior to the Pod starting up and mounting the NFS share. The directory is created for you.
Copy the above content into a file called deployment.yaml and adjust your settings to fit your environment (server/path) and then apply it to your cluster.
$ kubectl apply -f deployment.yaml
We need to get the name of the Pod.
$ kubectl get pods NAME READY STATUS RESTARTS AGE busybox-6875c8c8dd-zs7bw 1/1 Running 0 6m30s
Next we will exec into the Pod to look at the mounted share.
$ kubectl exec -it busybox-6875c8c8dd-zs7bw -- /bin/sh / # ls /files Documents Downloads Linux Pictures lost+found