Nfs K8s
If you want a minimal Ubuntu setup just to run an NFS server. Here’s how you can quickly set that up on a VM or bare metal:
⸻
Step 1: Install Ubuntu Server (minimal) • Download Ubuntu Server ISO from ubuntu.com • Install with default settings, no GUI, minimal install.
⸻
Step 2: Install NFS server
Log in to your Ubuntu machine, then:
sudo apt update sudo apt install nfs-kernel-server
⸻
Step 3: Prepare export directory
Choose or create the folder you want to share, e.g., /srv/nfs:
sudo mkdir -p /srv/nfs sudo chown nobody:nogroup /srv/nfs sudo chmod 755 /srv/nfs
Put your files (or ISO, whatever) inside /srv/nfs.
⸻
Step 4: Configure NFS exports
Edit /etc/exports:
sudo nano /etc/exports
Add a line like this to share /srv/nfs to your local network (replace with your subnet):
/srv/nfs 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)
• rw = read/write access
• sync = write changes immediately
• no_root_squash = clients can access as root (optional, use with care)
Save and exit.
⸻
Step 5: Apply export rules
sudo exportfs -ra
⸻
Step 6: Start and enable NFS server
sudo systemctl restart nfs-kernel-server sudo systemctl enable nfs-kernel-server
⸻
Step 7: Firewall (if enabled)
Allow NFS ports:
sudo ufw allow from 192.168.1.0/24 to any port nfs
⸻
Now your Ubuntu NFS server is ready.
Clients on the specified subnet can mount the share like:
sudo mount your.nfs.server.ip:/srv/nfs /mnt
⸻
If You want to mount an external NFS share inside your Kubernetes cluster so your pods can use it as persistent storage.
Here’s a simple way to do it:
⸻
Step 1: Create a PersistentVolume (PV) for the NFS share
Replace your.nfs.server.ip with your actual NFS server IP or hostname.
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 100Gi # Set this according to your NFS share size or quota
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: your.nfs.server.ip
path: /srv/nfs # The exported directory on the NFS server
⸻
Step 2: Create a PersistentVolumeClaim (PVC) to request the storage
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
⸻
Step 3: Use the PVC in your Pod or Deployment
Example Pod manifest using the PVC:
apiVersion: v1
kind: Pod
metadata:
name: nfs-client
spec:
containers:
- name: app
image: busybox
command: [ "sleep", "3600" ]
volumeMounts:
- name: nfs-storage
mountPath: /mnt/nfs
volumes:
- name: nfs-storage
persistentVolumeClaim:
claimName: nfs-pvc
⸻
Notes: • Make sure your NFS server allows connections from your Kubernetes nodes (firewall, export permissions). • ReadWriteMany access mode allows multiple pods to mount the volume simultaneously. • You might want to adjust storage sizes in PV and PVC to fit your needs. • If your NFS server hostname isn’t resolvable in your cluster, use the IP address.
⸻