An NFS (Network File System) is one of the most useful volume types in Kubernetes.
To mount a directory shared from an NFS server to a container running in a Kubernetes Pod it is required to do the following:
- Add the NFS volume to the Pod.
- Set the NFS server and path to the share.
- Mount the NFS volume in the container.
This note shows how to mount the NFS in the Kubernetes Pod by creating the appropriate manifest file in YAML.
Cool Tip: How to troubleshoot when a Deployment is not ready and is not creating Pods on a Kubernetes cluster! Read more →
Mount NFS in Kubernetes Pod
The snippet below shows the minimal Pod definition with the Nginx container and the mounted NFS volume:
# pod.yml --- apiVersion: v1 kind: Pod metadata: name: nginx labels: name: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 # Mount the NFS volume in the container volumeMounts: - name: nfs-share mountPath: /mnt/nfs-share # Add the NFS volume to the Pod volumes: - name: nfs-share # Set the NFS server and path to the share nfs: server: nfs.server.example.tld path: /nfs-share
The above Pod definition creates a container with the shared folder from the NFS server mounted at
Cool Tip: How to
kubectl apply all files in a directory! Read more →