NFS as Kubernetes Persistent Storage

Khimananda Oli 8 min read Database
NFS as Kubernetes Persistent Storage

By Khimananda Oli | Last reviewed: August 2026

NFS as Kubernetes Persistent Storage remains a pragmatic choice for teams needing shared, read-write-many (RWX) volumes without the complexity of distributed block storage. While cloud-native CSI drivers like EBS or Ceph RBD dominate high-performance database workloads, NFS provides a lightweight, protocol-native solution for configuration sharing, media assets, and legacy application migration. This guide covers the exact configuration, security hardening, and operational guardrails required to run NFS reliably in production clusters.

NFS Server/srv/nfs/k8s-dataExport: 10.0.0.0/24(rw)UID/GID MappingKubernetes ClusterNode Akubelet + NFS ClientNode Bkubelet + NFS ClientPod (RWX Mount)PVC: nfs-shared-dataPod (ROX Mount)Config / AssetsNFS v4.2 / TCP 2049
High-level architecture of NFS as Kubernetes Persistent Storage showing server exports, node clients, and pod mount topology.

How do you configure NFS as Kubernetes Persistent Storage?

The most reliable approach treats the NFS backend as infrastructure, not an afterthought. Before writing any YAML, verify that every cluster node has the nfs-common (Debian/Ubuntu) or nfs-utils (RHEL/CentOS) package installed. Missing client utilities are the single most frequent cause of ContainerCreating hangs when using Kubernetes persistent volumes and storage. Once prerequisites are met, define the storage layer declaratively.

Create the PersistentVolume definition

Static provisioning gives you explicit control over server IPs, paths, and mount options. This is preferred for compliance-sensitive environments where audit trails must map specific volumes to specific backends.

<!-- nfs-pv.yaml -->
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-shared-assets
  labels:
    type: nfs
    app: media-assets
spec:
  capacity:
    storage: 500Gi
  accessModes:
    - ReadWriteMany
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - nfsvers=4.2
    - rsize=1048576
    - wsize=1048576
    - hard
    - timeo=600
    - retrans=2
    - noatime
  nfs:
    server: 10.0.1.50
    path: /srv/nfs/k8s-media

Bind with a PersistentVolumeClaim

The PVC requests storage by label selector rather than size alone. This prevents accidental binding to unrelated NFS volumes in multi-tenant clusters.

<!-- nfs-pvc.yaml -->
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: media-assets-pvc
  namespace: content-platform
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 500Gi
  selector:
    matchLabels:
      type: nfs
      app: media-assets

Mount in your workload

Always set readOnly explicitly when the workload does not need write access. This reduces the blast radius of a compromised container and aligns with least-privilege principles I apply across SOC 2 engagements.

volumeMounts:
  - name: media-store
    mountPath: /app/data/media
    readOnly: false
volumes:
  - name: media-store
    persistentVolumeClaim:
      claimName: media-assets-pvc

What are the security best practices for NFS in Kubernetes?

NFS was designed for trusted LANs, not zero-trust cloud networks. Running it securely requires compensating controls at every layer. In my experience auditing Nepal-based fintech and global SaaS platforms, these five practices prevent the majority of NFS-related incidents.

  • Restrict exports by CIDR, never wildcard. Use /srv/nfs/k8s-data 10.0.0.0/24(rw,sync,no_subtree_check,root_squash). Never use * or 0.0.0.0/0.
  • Enforce root_squash universally. Map root to nobody to prevent container escape via UID 0. Only disable for specific service accounts with documented justification.
  • Isolate on a dedicated VLAN or subnet. NFS traffic should never traverse the same network as public ingress or management planes. Use Kubernetes network policies to restrict pod-to-NFS communication to only namespaces that require it.
  • Encrypt in transit for cross-zone or hybrid setups. Use NFSv4.2 with Kerberos (krb5p) or tunnel through WireGuard/IPsec. Plain NFS over the open internet is unacceptable for any regulated workload.
  • Audit export access logs. Enable nfsd logging and forward to your centralized stack. Correlate mount events with pod scheduling logs for forensic readiness. See structured logging best practices for schema guidance.
Network LayerVLAN IsolationCIDR Export RulesProtocol LayerNFSv4.2 + KerberosTCP 2049 OnlyIdentity Layerroot_squash EnabledUID/GID ConsistencyAudit Layernfsd LoggingSIEM IntegrationDefense-in-Depth Validation Checklist✓ No wildcard exports — CIDR-only in /etc/exports✓ root_squash active on all production shares✓ NetworkPolicy restricts egress to NFS server IP:2049✓ TLS/Kerberos enabled for cross-subnet mounts✓ Mount logs forwarded to Graylog/Loki with pod correlation
Layered security model for hardening NFS as Kubernetes Persistent Storage across network, protocol, identity, and audit domains.

When should you use NFS versus CSI drivers like Longhorn or RBD?

Choosing between NFS and block-based CSI drivers is an architectural decision, not a preference. Each has failure modes that matter differently depending on your workload profile. The table below reflects real trade-offs observed across production clusters in 2026.

CriteriaNFS (Native / CSI)Block CSI (Longhorn, RBD, EBS)
Access ModeRWX native, multi-pod concurrentRWO default; RWX requires extra layer
Performance (IOPS)Low–Medium, network-boundHigh, local NVMe or provisioned IOPS
Latency SensitivityPoor for databases, queuesExcellent for OLTP, indexing
Operational ComplexityLow (single server, standard protocol)High (replication, recovery, upgrades)
Data LocalityExternal to clusterInternal, hyper-converged options
Compliance Audit TrailSimple export logs, file-levelVolume snapshots, encryption-at-rest metadata
Best ForConfigs, media, legacy apps, shared cachesDatabases, stateful sets, high-throughput ETL

If your workload requires sub-millisecond latency or strong consistency guarantees, skip NFS entirely and evaluate Longhorn distributed storage for Kubernetes or your cloud provider’s managed block service. NFS excels when multiple pods must read and write the same files concurrently, and when operational simplicity outweighs raw throughput.

How do you troubleshoot NFS mount failures in Kubernetes?

NFS issues manifest as pods stuck in ContainerCreating, CrashLoopBackOff after mount timeouts, or silent data corruption. Follow this ordered diagnostic sequence before restarting services or redeploying.

  1. Verify node-level connectivity first. SSH into the affected node and run showmount -e 10.0.1.50. If this fails, the problem is network/firewall/export config — not Kubernetes. Check nfs-client installation and kernel module status (lsmod | grep nfs).
  2. Inspect kubelet logs for mount errors. Run journalctl -u kubelet --since "1 hour ago" | grep -i nfs. Look for mount.nfs: access denied (export permissions), server not responding (network/timeout), or stale file handle (server rebooted without client remount).
  3. Validate PV/PVC binding status. Use kubectl get pv,pvc -A. A PVC in Pending with no matching PV indicates label mismatch or capacity discrepancy. A PV in Available but unbound suggests access mode incompatibility.
  4. Test mount manually with identical options. Copy the mountOptions from your PV spec and run mount -t nfs -o nfsvers=4.2,rsize=1048576,wsize=1048576,hard,timeo=600 10.0.1.50:/srv/nfs/k8s-media /mnt/test. This isolates whether the issue is Kubernetes-specific or fundamental to the NFS configuration.
  5. Check for UID/GID mismatches. Containers running as non-root may lack write permissions if the NFS export directory ownership doesn’t match the pod’s runAsUser. Set consistent ownership on the server: chown -R 1000:1000 /srv/nfs/k8s-media and enforce securityContext.runAsUser: 1000 in your pod spec.

A common mistake is relying on soft mounts to avoid hangs. Soft mounts return I/O errors to the application instead of retrying, which causes silent data loss in write-heavy workloads. Always use hard mounts with appropriate timeo and retrans values unless your application explicitly handles partial writes and has its own retry logic.

Workload Storage Decision MatrixChoose NFS When...• Multiple pods need RWX access• Legacy app requires POSIX file API• Ops team lacks distributed storage expertise• Budget prioritizes simplicity over IOPSAvoid NFS When...• Database or queue backend storage• Sub-ms latency required• Strong consistency guarantees needed• High IOPS (>5K) sustained workloadHybrid Approach• Block for DB, NFS for configs/assets• Tiered storage by access pattern• Cache hot data locally, cold on NFS• Compliance-driven separationPerformance Reality Check (2026 Benchmarks)NFS v4.2 over 10GbE: ~800 MB/s sequential, ~2K IOPS random 4KNVMe Block CSI (local): ~3 GB/s sequential, ~100K+ IOPS random 4KCloud Block (gp3/io2): Provisioned IOPS up to 64K, latency <1msRule: If your app needs >5K IOPS or <2ms p99 latency, NFS is wrong tool
Decision framework and performance benchmarks for selecting NFS as Kubernetes Persistent Storage versus block storage alternatives.

Practical Next Steps for Production NFS Deployments

NFS as Kubernetes Persistent Storage works reliably when treated as a first-class infrastructure component with defined ownership, monitoring, and change control. Start by documenting your NFS server lifecycle: who owns patching, how exports are version-controlled, and what the failover procedure is if the primary server dies. Automate client package installation across nodes using your existing configuration management — manual installs drift and cause outages during scale-up events. Implement mount option standards as OPA policies or admission webhooks to prevent developers from accidentally deploying soft mounts or insecure versions. Finally, integrate NFS metrics into your observability stack; track nfsstat counters, mount latency percentiles, and export utilization alongside your application SLOs. If your team needs help designing a compliant, auditable storage layer that balances developer velocity with operational safety, reach out to discuss your architecture.

Frequently Asked Questions

Yes, for stateless apps and shared read-write volumes. Avoid for high-IOPS databases. Use CSI drivers like nfs-subdir-external-provisioner v4.0+ with proper server tuning and network isolation to ensure reliability in production clusters.

Deploy an NFS server or use managed NAS. Install the NFS CSI driver via Helm. Create a StorageClass pointing to your NFS export. Define PersistentVolumeClaims referencing that class. Pods mount volumes dynamically through the provisioner without manual PV creation.

NFS lacks POSIX locking consistency and has higher latency than block storage. Metadata operations bottleneck under heavy concurrent access. Expect 30-50% lower throughput versus local SSDs. Tune rsize/wsize to 1048576 and enable async mounts for better performance.

Yes, NFS supports ReadWriteMany access mode natively. Multiple pods across nodes can read and write concurrently. Ensure applications handle file locking correctly since NFSv4 advisory locks are not always enforced reliably by all Kubernetes CSI implementations.

NFS offers shared access and simplicity but lower performance. EBS provides high IOPS for single-node databases. Ceph delivers distributed block and object storage with stronger consistency. Choose NFS for shared configs or media; pick block storage for transactional workloads requiring strict durability guarantees.

NFS traffic is unencrypted by default. Unauthorized clients can mount exports if IP restrictions fail. Root squashing misconfigurations expose host filesystems. Always enable Kerberos authentication, restrict exports by CIDR, run NFS over TLS, and apply NetworkPolicies limiting pod-to-server communication.

Check CSI driver logs and NFS server connectivity. Verify export permissions include the node IPs. Confirm StorageClass parameters match server path. Ensure nfs-utils is installed on all worker nodes. Validate that the provisioner pod has RBAC permissions to create PersistentVolumes.

No, standard NFS lacks native snapshot APIs. Some enterprise NAS systems expose snapshot functionality through custom CSI drivers. For most open-source setups, implement application-level backups or use Velero with restic to capture consistent point-in-time copies of NFS-backed data.

Use NFSv4.1 or v4.2 for improved session management, parallel I/O, and better lock recovery. Avoid NFSv3 due to weak security and stateless design. Configure servers with pNFS support when available to distribute data across multiple storage targets efficiently.

Check network latency between nodes and NFS server using ping and traceroute. Monitor server CPU and disk utilization with iostat. Review mount options for correct rsize/wsize values. Inspect dmesg for stale file handle errors. Test raw throughput with dd outside containers first.

Yes, if AllowVolumeExpansion is true in the StorageClass and the NFS backend supports it. Most subdir external provisioners allow expansion by updating quota or directory limits. Edit PVC spec.resources.requests.storage and wait for FileSystemResizePending condition before restarting pods.

Managed services like AWS EFS or Azure Files reduce operational overhead but cost more per GB. Self-hosted NFS on existing infrastructure saves money at scale but requires maintenance. Calculate total cost including backup, monitoring, and engineering time before choosing between options.

Mounted volumes become inaccessible and pods hang indefinitely on I/O operations. Kubernetes cannot reschedule affected pods automatically. Implement health checks, use soft mounts with timeouts cautiously, and deploy HA NFS with DRBD or Pacemaker to minimize downtime impact.

Yes, every node mounting NFS volumes requires nfs-utils or nfs-common package. The CSI driver handles provisioning but kernel modules perform actual mounts. Missing utilities cause MountFailed events. Include this dependency in node bootstrapping scripts or machine images for reliable cluster operations.

Use Velero with restic integration for incremental encrypted backups to S3-compatible storage. Schedule CronJobs running rsync for simple file-level copies. Enterprise NAS solutions offer native replication. Always test restore procedures quarterly to verify backup integrity and recovery time objectives meet business requirements.