Shared filesystem
An NFS server exports one directory that many Pods can mount through a PV and PVC.
Use an NFS server with Kubernetes persistent volumes to provide shared storage across Pods and nodes.
k8s/labs/storage/nfs-pv-pvc.yaml — NFS PV, PVC, and Pod manifestAn NFS server exports one directory that many Pods can mount through a PV and PVC.
NFS is a practical way to demonstrate RWX behavior in labs and on-premises clusters.
Data management, backup, and access control are organized around the exported server path.
Install the server, export a directory, and make sure cluster nodes can reach it.
Install NFS client tools and verify a node can mount the exported path.
Point a PersistentVolume at the server IP and export path.
The claim requests shared storage and binds to the NFS-backed volume.
Many Pods can use the same underlying files across nodes and workloads.
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
path: /mnt/nfs_share
server: 192.168.1.100
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
name: nfs-pod
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: nfs-volume
mountPath: /usr/share/nginx/html
volumes:
- name: nfs-volume
persistentVolumeClaim:
claimName: nfs-pvc
| Topic | HostPath | NFS |
|---|---|---|
| Data location | One node filesystem | Network share on a server |
| Multi-node access | No practical shared access | Yes, designed for it |
| RWX fit | Poor | Strong |
| Typical lesson | Local persistence | Shared storage |
Show that the same data remains visible even when Pods run on different nodes.
Teach why some backends support shared writable access while others do not.
Use NFS when many Pods need to coordinate around common files, logs, or assets.