Step-by-Step Guide to Deploying NFS-Backed Nginx on Kubernetes
This article provides a detailed tutorial on setting up an NFS server, configuring a Kubernetes deployment of Nginx with NFS volume mounts, and explains static versus dynamic persistent storage in K8s, complete with command examples and YAML configuration.
This guide walks you through deploying an NFS server, mounting its directory, and then running an Nginx deployment on a Kubernetes master node that uses the NFS share as its web root.
1. Deploy an NFS server and configure the export directory
Run the following command to verify the NFS service:
ps -ef | grep nfs
Export the NFS path:
exportfs
Typical output shows the exported paths, for example:
/nfs/data 192.168.29.0/24
/nfs/data <world>
2. Deploy Nginx on the Kubernetes master and mount the NFS share
Create a deployment manifest (save as nfs-nginx.yaml ):
apiVersion: v1
kind: Deployment
metadata:
name: nginx-depoyment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
ports:
- containerPort: 82
volumes:
- name: www
nfs:
server: nfsIP
path: /nfs/dataApply the manifest:
kubectl apply -f nfs-nginx.yaml
Output:
deployment.apps/nginx-depoyment created
Inspect the pod:
kubectl describe pod nginx-depoyment-697cb7b8c5-g7hm7
List all pods to verify the deployment is running:
kubectl get pods
Enter the pod’s shell and check the mounted directory:
kubectl exec -it nginx-depoyment-697cb7b8c5-g7hm7 /bin/bash
ls /usr/share/nginx/html/
You will see the files that were previously stored by a MySQL deployment, confirming the NFS mount works.
Understanding Kubernetes Persistent Storage
Kubernetes supports two main types of persistent volumes: static volumes, which are manually created and bound via PV/PVC (as demonstrated above), and dynamic volumes, which are provisioned on‑the‑fly using a StorageClass that abstracts the underlying network storage.
For further reading, see the recommended articles:
Understanding K8s MySQL 8.0 Deployment
Kubernetes Deploying Stateless Applications
K8s Autoscaling & Rollback
Simple K8s Dashboard Deployment
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.