Course contentsShow
← Docker, Kubernetes & CI/CD
Lesson 329 of 8025. Advanced Kubernetes ConfigurationFree lesson

Exposing Network File Systems as Persistent Volumes

Integrate NFS or other network-attached storage solutions to provide shared filesystems that multiple pods can mount simultaneously across different cluster nodes.

In this lesson, you will learn how to bridge the gap between external Network File Systems (NFS) and your Kubernetes pods to enable shared, cross-node data persistence.

The Problem of Isolated Storage

Up until now, we’ve looked at standard PersistentVolumes that often map to block storage (like cloud disks). The challenge with block storage is that it is typically "ReadWriteOnce"—it can only be mounted by a single node at a time. If you have an application that needs to scale across multiple nodes and requires all pods to read from and write to the exact same shared files simultaneously, block storage falls short.

The NFS Solution

A Network File System (NFS) acts as a centralized server that serves files over the network. By integrating NFS as a PersistentVolume (PV), you provide a shared mount point that ignores physical node boundaries. Because NFS is inherently designed for multi-client access, it allows your pods to mount the same filesystem in ReadWriteMany mode.

To set this up, you define a PV that points directly to your NFS server’s IP address and exported path:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.1.50 # Your NFS server IP
    path: "/exports/shared-data"

Why This Matters

When you use ReadWriteMany with an NFS backend, Kubernetes treats the remote directory as a local mount point within your pod. If Pod A on Node 1 writes a log file to the mount, Pod B on Node 2 can instantly see and read that file. This is crucial for distributed applications, shared configuration repositories, or content management systems where multiple instances must stay synchronized on the same dataset.

By decoupling the storage layer from the compute layer using NFS, you ensure that your cluster remains flexible, allowing workloads to migrate between nodes without losing access to their common data source.

Key Takeaway: Integrating NFS as a Persistent Volume enables the ReadWriteMany access mode, allowing multiple pods across different cluster nodes to share and synchronize the same filesystem seamlessly.