NFS-Share (shared storage)
April 9, 2021 | StackPreparation of a USB 3.x storage
By default one could use the Pi's internal SD-card for storage. But, for many reasons - as stabillity and speed - external storage like an USB 3.x stick on a Pi 4 would be preferable.
Find the node you would like to hold your storage device, and SSH in to the node. And locate the storage device:
sudo fdisk -l
and you would se something like the above.
To partition the USB to ext4 linux format, do the following:
sudo mkfs.ext4 /dev/sda2
Now list all block attributes:
sudo blkid
Create a dir for mounting:
sudo mkdir /mnt/storage
Find the /dev/sda2 line and copy the UUID (ex. UUID="1c611a1a-fbd9-3a22-b527-885cb72c445b"). To make sure the USB is always auto mounted we will add it to fstab (read more about each part of the line). Substitude the UUID with the above outcome and "sudo nano /etc/fstab" and add the following line:
UUID=1c611a1a-fbd9-3a22-b527-885cb72c445b /mnt/storage ext4 defaults,auto,users,rw,nofail 0 0
Make the storage accesible:
sudo chmod 777 /mnt/storage
This should mount the storage after reboot, to the location /mnt/storage.
NFS share
Sharing a volume/storage with other machines on the network.
Install nfs kernel server on the Pi with the storage (lets call it the server in this context).
sudo apt install nfs-kernel-server
sudo nano /etc/exports
/mnt/storage 192.168.68.120/29(rw,sync,no_subtree_check)
if you are not sure about netmasking just allow access to the whole range (something like 192.168.0.1/24).
Client if NOT K8S
On the client side (on all machines that should have access to the storage) some libraries needs to be installed.
sudo apt install nfs-common
And make sure to mount the storage into the machine. Make the directory to mount into ex:
sudo mkdir /mnt/storage
and try and mount the shared directory:
sudo mount -t nfs 192.168.68.123:/mnt/storage /mnt/storage
If everything went as it should. You will be able to access the drive on the local machine.
To make this access persistent after reboot, we need to make a fstab entry:
sudo nano /etc/fstab
and put in the line in the bottom:
192.168.68.123:/mnt/storage /mnt/storage/ nfs defaults 0 0
Now reboot the system and see if the share is mounted..
Client if K8s:
Install nfs-common on all clients ex. all worker nodes:
sudo apt install nfs-common
To automate the process of generating storageClass and provisioner we use the: https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner project.
and deploy it with helm.
$ helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
$ helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
--set nfs.server=x.x.x.x \
--set nfs.path=/exported/path
Then you should be ready to create PVC's to your deployments.
Troubleshooting
There can be a wide range of issues if the nfs store stops to work. The following is some debuging advices.
- Check that nfs-common is running (and start it if it is not).
sudo systemctl status nfs-common.service
The service may be "masked". You can unmask the service by:
sudo systemctl unmask nfs-common.service
and try to restart.. This might not be enough, then:
sudo rm /lib/systemd/system/nfs-common.service
sudo systemctl daemon-reload
sudo systemctl start nfs-common sudo systemctl enable nfs-common
and then a reboot may be nessesary:
sudo reboot