NFS server on a Kubernetes node?
6,450
You can setup a pod
that will act as NFS server.
There is a ready image on Docker Hub cpuguy83/nfs-server.
To use it you need to created a service to expose the NFS server to pods inside the cluster:
kind: Service
apiVersion: v1
metadata:
name: nfs-service
spec:
selector:
role: nfs
ports:
# Open the ports required by the NFS server
# Port 2049 for TCP
- name: tcp-2049
port: 2049
protocol: TCP
# Port 111 for UDP
- name: udp-111
port: 111
And a pod
which will run the image:
kind: Pod
apiVersion: v1
metadata:
name: nfs-server-pod
labels:
role: nfs
spec:
containers:
- name: nfs-server-container
image: cpuguy83/nfs-server
securityContext:
privileged: true
args:
# Pass the paths to share to the Docker image
- /exports
An example of a pod
using the NFS volume:
kind: Pod
apiVersion: v1
metadata:
name: pod-using-nfs
spec:
# Add the server as an NFS volume for the pod
volumes:
- name: nfs-volume
nfs:
# URL for the NFS server
server: 10.108.211.244 # Change this!
path: /
# In this container, we'll mount the NFS volume
# and write the date to a file inside it.
containers:
- name: app
image: alpine
# Mount the NFS volume in the container
volumeMounts:
- name: nfs-volume
mountPath: /var/nfs
# Write to a file inside our NFS
command: ["/bin/sh"]
args: ["-c", "while true; do date >> /var/nfs/dates.txt; sleep 5; done"]
Related videos on Youtube
Author by
AVarf
Updated on September 18, 2022Comments
-
AVarf over 1 year
We have an in house Kubernetes cluster running on bare-metal, can I set up an NFS server on one of the nodes (either worker or master) in the cluster? If yes do I need to change anything in the cluster?
-
AVarf over 4 yearsThank you for your answer. I decided to go with StorageOS which takes care of everything and it can be run on cloud too but for my personal information I like to ask: Your link is just an NFS client and we need to pass the IP of the server to it, my question is can I put that server on one of the nodes or this is a bad prctice?