Kubernetes on Raspberry Pi 5— Part 2 Mount external storage
I have been using a Raspberry Pi 4 as a host for a Kubernetes for about two years. Recently I purchased the new Raspberry Pi 5. I plan to also setup Kubernetes on it so I can have a cluster with two nodes.
K3s on Raspberry Pi 5
Part 1 Install Raspberry Pi OS Lite 64-bit
Part 3 Install K3S on master node
I will be hosting a k3s deployment for my cluster. I have already installed Raspberry Pi OS Lite 64-bit, so the next step is to prepare the storage for my k3s cluster.
The drive that I am using is a Western Digital 5TB Elements external hard disk connected using a USB cable to one of the USB 3 ports on the board.
- [Optional] Formatting the drive
If your drive is not formatted yet you will have to run the following commands after connecting the drive to your board. Running the command below will allow finding the partition of the drive.
sudo fdisk -l
In the output of the command your hard drive partition should be at the bottom. For example mine is /dev/sda.
Disk /dev/sda: 4.55 TiB, 5000947302400 bytes, 9767475200 sectors
Disk model: Elements 2620
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Now using the command below the drive will be formatted using the ext4 file system.
mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/sda
The two options that I am using (lazy_itable_init=0,lazy_journal_init=0) initialise the inodes and the journal immediately during creation. This will slow down the formatting process, the kernel will not have to finish initializing the file system in the background when the file system is first mounted.
2. Create mount point
Now we create a directory where the external drive will be mounted (/mnt/hdd).
mkdir /mnt/hdd
3. Setup automatic mount
Because we need to have the drive to be mounted when the board starts we must setup automatic mounting using the /etc/fstab file. First we will run the command bellow to find the UUID of the external drive:
blkid
You will see a map where the id is the drive partition and the value is a list of properties including the UUID.
/dev/sda: UUID="<UUID value>" BLOCK_SIZE="4096" TYPE="ext4"
Open the /etc/fstab file using your preferred text editor. I am using nano.
sudo nano /etc/fstab
At the end of this file you will have to add a new line similar to the one below, but replacing <UUID value> with the one corresponding to your partition (the UUID from the blkid command output).
UUID=<UUID value> /mnt/hdd ext4 defaults,nofail,async,noatime,nodiratime 0 0
If you want to understand the meaning of the mount options that I am using (defaults,nofail,async,noatime,nodiratime) you can use the command man mount inside the terminal. You can also chose to use different options if you find that these do not suit you needs.
Now the drive is ready to be mounted. You can either run this command:
sudo mount -a
Or you can restart the board:
sudo reboot
And the drive will be mounted at boot time.
4. Sharing the drive
I order for the drive to be accessed by other boards in the cluster I am sharing it using NFS. In order to do this I need to first install nfs-kerner-server.
sudo apt-get install nfs-kernel-server
Next I go into the /etc/exports file:
sudo nano /etc/exports
And add the following line:
/mnt/hdd 192.168.0.0/24(rw,no_root_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
This will allow only clients in the “192.168.0.xxx” subnet to connect to the drive.
Lastly I am restarting the NFS server in order to make it pickup the new setup.
sudo systemctl restart nfs-kernel-server
5. Mounting the shared drive
On the client boards I will install an NFS client:
sudo apt-get install nfs-common
Next I will create a mount point. I will use the same directory as on the server board, /mnt/hdd.
sudo mkdir
Like I did on the server board, I will open the /etc/fstab file:
sudo nano /etc/fstab
And add the following line where you will have to replace <SERVER IP> with the IP of your server board:
<SERVER IP>:/mnt/hdd /mnt/hdd nfs auto,bg,nofail,rw,async,retry=10,x-systemd.automount,x-systemd.idle-timeout=60s 0 0
After rebooting the client board the shared drive should be mounted.