Install the needed kernel module for creating NFS mounts
sudo apt update
sudo apt install nfs-kernel-server
Start up the NFS server
sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server
Create the mount path on the server
sudo mkdir -p /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
Add to exports
$ sudo vim /etc/exports
/mnt/nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)
$ sudo exportfs -ra
Mount on the client
sudo mkdir /mnt/nfs_mount
sudo mount <host_machine_ip>:/mnt/nfs_share /mnt/nfs_mount
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 10Gi # Adjust the storage size as needed
accessModes:
- ReadWriteMany # Allows multiple pods to read and write from the NFS volume
persistentVolumeReclaimPolicy: Retain
nfs:
path: /mnt/nfs_share # Path to the NFS directory on the host
server: <host_machine_ip> # NFS server IP address
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi # Match the requested storage size with the PV
K3s only comes with the local-storage storage class which means that the ReadWriteMany access for our PVC won’t work and will need to install another storage class.