CODE/2024-01-15

Setting Up an NFS Server for Kubernetes

Network File System (NFS) lets multiple machines access a shared directory over a network. It can provide shared storage for Kubernetes workloads that may move between nodes.
This example describes a small CentOS 7 test setup with one server and one client. CentOS 7 is end-of-life; use a supported distribution and a production-ready storage design for new deployments. Replace the example addresses and network with your own.

Configure the NFS server

Install the NFS utilities and create a shared directory:
bash_snippet
Bash · 2 lines|
sudo yum install -y nfs-utils
sudo mkdir -p /data/nfs
Add an export to /etc/exports, restricting access to your client network:
plain text_snippet
Plain Text · 1 line|
/data/nfs 192.0.2.0/24(rw,sync,root_squash)
192.0.2.0/24 is a documentation network, not an actual client network. Configure directory ownership and permissions for the client users who need to write. root_squash maps remote root to an unprivileged user; do not disable it merely to make a test work.
Start the services and load the export:
bash_snippet
Bash · 3 lines|
sudo systemctl enable --now rpcbind nfs-server
sudo exportfs -ra
sudo exportfs -v
Allow the NFS traffic needed by your chosen protocol version through the firewall, restricted to trusted clients. NFSv3 may need additional RPC services and ports; do not expose an NFS server directly to the internet.

Mount from a client

Install nfs-utils on the client and mount the export. Replace the address with your NFS server's actual address:
bash_snippet
Bash · 4 lines|
sudo yum install -y nfs-utils
sudo mkdir -p /data/nfsmount
sudo mount -t nfs 192.0.2.10:/data/nfs /data/nfsmount
mount | grep /data/nfsmount
Write a test file as a user with permission on the export and verify it on the server:
bash_snippet
Bash · 1 line|
printf 'hello NFS\n' > /data/nfsmount/test.txt
When finished testing, unmount the client:
bash_snippet
Bash · 1 line|
sudo umount /data/nfsmount

Use NFS with Kubernetes

A Kubernetes persistent volume can reference an existing NFS export. Dynamic provisioning requires a suitable NFS CSI driver or provisioner; installing an NFS server alone does not create a StorageClass. In a management UI such as Kuboard, configure the provisioner's NFS server address and exported path according to the installed provisioner's requirements.
Validate permissions, network access, backup, performance, and availability before using the storage for production workloads.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·