A common need is to share files between different containers. There are many ways to accomplish this.

If you only need to share a folder between pods running on the same node you can use local node shares.

NFS shares is one of the options when you are looking to share files across pods in different node.

Setup a NFS Server

In this example we will assume an ubuntu server (16.04+):

sudo apt-get update 
sudo apt-get install nfs-kernel-server

Create the shared folder:

sudo mkdir /nfs 
sudo chown nobody:nogroup /nfs

Modify /etc/exports to include:

/nfs    *(rw,sync,no_subtree_check,no_root_squash) 

Restart daemon:

sudo systemctl restart nfs-kernel-server 

Another alternative it is to run the nfs-server on a container and, for example, use a local node share for the files (will try this later)

Make sure it is working

It is always a good idea to test the NFS share and the make sure that there isn’t any firewall rules blocking access to the server. One idea is to ssh into one of the nodes and try to mount the share.

On a ubuntu server, make sure to install the client tools:

sudo apt-get install nfs-common 

Rancher

If you are using Rancher to manager your cluster, follow these instructions to deploy a container with access to your shared folder.

Add Volume

First, let’s create the “volume”.

Select your cluster, storage and then click “Add Volume”:

Create a Persistent Volume

The path will be the “root of your share”. If you enter “/”, the mount will will have a “nfs” folder. You can specify “/nfs” and the mount will “start” on it.

In this case the NFS server is at 172.30.0.209. If you run the nfs-server as a container you should be able to rely on kube-dns to resolve the name.

Create a test container

Create the deployment using the busybox image, and mount the volume by clicking “Add Volume” and selecting “Add a new persistent volume (claim) from the drop-down menu.

Define the volume claim:

Add a Volume Claim

You can mount the same volume in several different pods. After the volume claim is created, just select “Use an existing persistent volume claim” when adding the volume to the container.

References


0 Comments

Leave a Reply

Avatar placeholder