Cloud Native 3 min read

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.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Mounting NFS in a Kubernetes Pod and Exposing It as a Service

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/nfs

2. Expose the pod as a service

kubectl expose pod haha-nfs -n dev --port=80 --target-port=80 --type=NodePort

3. Verify the NFS share contents

# ls /data/nfs
access.log  error.log

4. 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.

cloud nativeKubernetesstorageyamlPodNFS
Practical DevOps Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.