Mounting NFS in a Kubernetes Pod and Exposing It as a Service
This guide explains what NFS is, how to create a Kubernetes pod that mounts an NFS share, expose the pod via a NodePort service, and verify the NFS logs using standard Linux commands.
NFS (Network File System) is a TCP/IP‑based protocol that allows remote file systems to be accessed as if they were local directories, relying on RPC and typically requiring the installation of nfs-utils and rpcbind packages.
The following steps show how to create a pod that mounts an NFS share, expose it, and check the logs.
1. Create a pod with an NFS volume
apiVersion: v1
kind: Pod
metadata:
name: haha-nfs
namespace: dev
labels:
apps: nginx-nfs
spec:
containers:
- name: nginx
image: nginx:1.20
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
volumes:
- name: logs-volume
nfs:
server: 172.31.56.52
path: /data/nfs2. Expose the pod as a service
kubectl expose pod haha-nfs -n dev --port=80 --target-port=80 --type=NodePort3. Verify the NFS share contents
# ls /data/nfs
access.log error.log4. Access the Nginx service and view NFS logs
# tail -f /var/log/nginx/access.log
172.31.56.207 - - [05/Sep/2023:09:56:25 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"The article ends with a reminder to like, share, and follow for more Kubernetes and cloud‑native tutorials.
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.