Table of Contents

Step-by-Step Guide to Setting Up NFS Server and Client

NFS (Network File System) enables file and directory sharing across a network. Here's the guide to set it up.

Prerequisites

Setting Up the NFS Server

1. Install NFS Kernel Server

Update and install:

 sudo apt update
 sudo apt install nfs-kernel-server 

2. Create and Configure the Export Directory

Create the directory:

 sudo mkdir -p /srv/nfs/share

Set ownership and permissions:

 sudo chown nobody:nogroup /srv/nfs/share
 sudo chmod 777 /srv/nfs/share

3. Edit NFS Exports

Add the following to `/etc/exports` (replace `<client_ip>`):

 /srv/nfs/share <client_ip>(rw,sync,no_subtree_check)

Export the changes:

 sudo exportfs -a

4. Start NFS Service

Enable and start the service:

 sudo systemctl enable nfs-kernel-server
 sudo systemctl start nfs-kernel-server

5. Configure Firewall

Allow NFS traffic:

 sudo ufw allow from <client_ip> to any port nfs

Enable UFW and check the status:

 sudo ufw enable
 sudo ufw status
  

Setting Up the NFS Client

The client in this case is the server where Kubernetes is installed and running.

1. Install NFS Common Package

Update and install:

 sudo apt update
 sudo apt install nfs-common

2. Create a Mount Point

Create the directory:

 sudo mkdir -p /mnt/nfs_clientshare
  

3. Mount the NFS Share

Mount the shared directory (replace `<nfs_server_ip>`):

 sudo mount <nfs_server_ip>:/srv/nfs/share /mnt/nfs_clientshare

4. Verify Mount

Check mounted filesystems:

 df -h | grep nfs_clientshare

List files in the mounted directory:

 ls /mnt/nfs_clientshare

Your NFS server and client setup is complete, enabling efficient file sharing over the network. Ensure regular updates and security checks for optimal performance.