Files
3engines_doc/docs/kubernetes/Create-and-access-NFS-server-from-Kubernetes-on-3Engines-Cloud.html.md
2025-07-04 09:34:25 +05:30

165 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Create and access NFS server from Kubernetes on 3Engines Cloud[🔗](#create-and-access-nfs-server-from-kubernetes-on-brand-name "Permalink to this headline")
=============================================================================================================================================================
In order to enable simultaneous read-write storage to multiple pods running on a Kubernetes cluster, we can use an NFS server.
In this guide we will create an NFS server on a virtual machine, create file share on this server and demonstrate accessing it from a Kubernetes pod.
What We Are Going To Cover[🔗](#what-we-are-going-to-cover "Permalink to this headline")
---------------------------------------------------------------------------------------
> * Set up an NFS server on a VM
> * Set up a share folder on the NFS server
> * Make the share available
> * Deploy a test pod on the cluster
Prerequisites[🔗](#prerequisites "Permalink to this headline")
-------------------------------------------------------------
No. 1 **Hosting**
You need a 3Engines Cloud hosting account with Horizon interface <https://horizon.3Engines.com>.
The resources that you require and use will reflect on the state of your account wallet. Check your account statistics at <https://portal.3Engines.com/>.
No. 2 **Familiarity with Linux and cloud management**
We assume you know the basics of Linux and 3Engines Cloud cloud management:
* Creating, accessing and using virtual machines
[How to create new Linux VM in 3Engines Dashboard Horizon on 3Engines Cloud](../cloud/How-to-create-new-Linux-VM-in-3Engines-Dashboard-Horizon-on-3Engines-Cloud.html.md)
* Creating security groups [How to use Security Groups in Horizon on 3Engines Cloud](../cloud/How-to-use-Security-Groups-in-Horizon-on-3Engines-Cloud.html.md)
* Attaching floating IPs [How to Add or Remove Floating IPs to your VM on 3Engines Cloud](../networking/How-to-Add-or-Remove-Floating-IPs-to-your-VM-on-3Engines-Cloud.html.md)
No. 3 **A running Kubernetes cluster**
You will also need a Kubernetes cluster to try out the commands. To create one from scratch, see [How to Create a Kubernetes Cluster Using 3Engines Cloud 3Engines Magnum](How-to-Create-a-Kubernetes-Cluster-Using-3Engines-Cloud-3Engines-Magnum.html.md)
No. 4 **kubectl access to the Kubernetes cloud**
As usual when working with Kubernetes clusters, you will need to use the **kubectl** command: [How To Access Kubernetes Cluster Post Deployment Using Kubectl On 3Engines Cloud 3Engines Magnum](How-To-Access-Kubernetes-Cluster-Post-Deployment-Using-Kubectl-On-3Engines-Cloud-3Engines-Magnum.html.md)
1. Set up NFS server on a VM[🔗](#set-up-nfs-server-on-a-vm "Permalink to this headline")
----------------------------------------------------------------------------------------
As a prerequisite to create an NFS server on a VM, first from the Network tab in Horizon create a security group allowing ingress traffic from port **2049**.
Then create an Ubuntu VM from Horizon. During the *Network* selection dialog, connect the VM to the network of your Kubernetes cluster. This ensures that cluster nodes have access to the NFS server over private network. Then add that security group with port **2049** open.
![nfs_server_2049.png](../_images/nfs_server_2049.png)
When the VM is created, you can see that it has private address assigned. For this occasion, let the private address be **10.0.0.118**. Take note of this address to later use it in NFS configuration.
Set up floating IP on the VM server, just to enable SSH to this VM.
2. Set up a share folder on the NFS server[🔗](#set-up-a-share-folder-on-the-nfs-server "Permalink to this headline")
--------------------------------------------------------------------------------------------------------------------
SSH to the VM, then run:
```
sudo apt-get update
sudo apt-get install nfs-kernel-server
```
In the NFS server VM create a share folder:
```
sudo mkdir /mnt/myshare
```
Change the owner of the share so that *nobody* is owner. Thus any user on the client can access the share folder. More restrictive settings can be applied.
```
sudo chown nobody:nogroup /mnt/myshare
```
Also change the permissions of the folder, so that anyone can modify the files:
```
sudo chmod 777 /mnt/myshare
```
Edit the */etc/exports* file and add the following line:
```
/mnt/myshare 10.0.0.0/24(rw,sync,no_subtree_check)
```
This indicates that all nodes on the cluster network can access this share, with subfolders, in read-write mode.
3. Make the share available[🔗](#make-the-share-available "Permalink to this headline")
--------------------------------------------------------------------------------------
Run the below command to make the share available:
```
sudo exportfs -a
```
Then restart the NFS server with:
```
sudo systemctl restart nfs-kernel-server
```
Exit from the NFS server VM.
4. Deploy a test pod on the cluster[🔗](#deploy-a-test-pod-on-the-cluster "Permalink to this headline")
------------------------------------------------------------------------------------------------------
Ensure you can access your cluster with **kubectl**. Have a file *test-pod.yaml* with the following contents:
**test-pod.yaml**
```
apiVersion: v1
kind: Pod
metadata:
name: test-pod
namespace: default
spec:
containers:
- image: nginx
name: test-container
volumeMounts:
- mountPath: /my-nfs-data
name: test-volume
volumes:
- name: test-volume
nfs:
server: 10.0.0.118
path: /mnt/myshare
```
The NFS server block refers to private IP address of the NFS server machine, which is on our cluster network. Apply the *yaml* manifest with:
```
kubectl apply -f test-pod.yaml
```
We can then enter the shell of the *test-pod* with the below command:
```
kubectl exec -it test-pod -- sh
```
and see that the *my-nfs-data* folder got mounted properly:
![image2023-6-1_17-6-3.png](../_images/image2023-6-1_17-6-3.png)
To verify, create a file *testfile* in this folder, then exit the container. You can then SSH back to the NFS server and verify that *testfile* is available in */mnt/myshare* folder.
![image2023-6-1_17-8-5.png](../_images/image2023-6-1_17-8-5.png)