Once you have created your Kubernetes cluster it’s time to handle persistent volumes and one way to store your data in a common safe place for all your Kubernetes services is an NFS storage.
About NFS Mount Volumes
NFS mounts work to share a directory between several servers. This has the advantage of saving disk space, as the home directory is only kept on one server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.
Lest do it with a new VM.
- Create a small new VM “Standard B1s (1 vcpus, 1 GiB memory)”
- Ensure the volume storage is enough for your purposes
- Ensure this new machine is accessible through your network
Time to set up the NFS Host
Ubuntu
sudo apt-get update sudo apt-get install nfs-kernel-server
Centos
yum install nfs-utils nfs-utils-lib
chkconfig nfs on
service rpcbind
start service nfs start
Subsequently, run several startup scripts for the NFS server
Now we will create the shared directory
Ubuntu and Centos
sudo mkdir /var/nfs/general
Next, we’ll dive into the NFS configuration file to set up the sharing of these resources.
nano /etc/exports
#add this for each folder you want to share
/var/nfs/general 10.1.6.4(rw,sync,no_root_squash,no_subtree_check)
These settings accomplish several tasks:
- rw: This option allows the client server to both read and write within the shared directory
- sync: Sync confirms requests to the shared directory only once the changes have been committed.
- no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
- no_root_squash: This phrase allows root to connect to the designated directory
Note: we need to add the IP of each server we want to share the NFS
Finally, in Centos run
exportfs -a
and Ubuntu
sudo systemctl restart nfs-kernel-server
Setting Up the NFS Client
Step One—Download the Required Software
Start off by using apt-get to install the NFS programs.
Centos yum install nfs-utils nfs-utils-lib
Ubuntu: sudo apt-get update
sudo apt-get install nfs-common
Step Two—Mount the Directories
Once the programs have been downloaded to the client-server, create the directory that will contain the NFS shared files mkdir -p /mnt/nfs/home
Then go ahead and mount it
mount 10.1.6.6:/var/nfs/general /mnt/nfs/home
You can use the df -h command to check that the directory has been mounted. You will see it last on the list.
df -h