Skip to content

phcollignon/nfs-server-minikube

Repository files navigation

NFS Server for Kubernetes (minikube)

Here is a minimalist NFS server for testing NFS Storage with Kubernetes (minikube)

Please note that this is only for testing, development and educational purposes.

It has been developed for the course "Deploying Statefull Application to Kubernetes" @PluralSight (to be published soon).

Environment

The environment consists of :

How to deploy

Please note that this environment has been tested only on Linux. If you are running macOS or Windows it is recommended to use a Linux VM.

  1. First, install Docker (version 18.09.1 or higher) if it is not already available on your platform
  2. Download and run minikube with docker driver
minikube start
  1. Run NFS server in Docker :

First make sure that NFS is supported by the kernel of your host machine (nfs & nfsd modules).
As root :

# modprobe nfs
# modprobe nfsd

Then launch the nfs-server container :

docker run -d --rm --privileged --name nfs-server  -v /var/nfs:/var/nfs  phico/nfs-server:latest

By default, the NFS share is mounted with a volume in a /var/nfs directory on your host. If you host does not allow this

  1. Add the nfs-server container to the minikube docker network :
docker network connect minikube nfs-server 
  1. Install Kubectl https://kubernetes.io/docs/tasks/tools/
  2. [Optional] Install NFS dynamic provisioner from nfs-subdir-external-provisioner/deploy directory :
kubectl apply -f rbac.yaml
kubectl apply -f deployment.yaml
kubectl apply -f storageClass.yaml

Credit to project : https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner.

  1. [Optional] Install NFS CSI Driver from csi-driver-nfs/deploy directory :
kubectl apply -f rbac-csi-nfs-controller.yaml
kubectl apply -f csi-nfs-driverinfo.yaml
kubectl apply -f csi-nfs-controller.yaml
kubectl apply -f csi-nfs-node.yaml

Credit to project : https://github.com/kubernetes-csi/csi-driver-nfs.

How to use

Please check the examples folder for following usages :

busybox-nfs.yaml Volume in a pod
busybox-nfs-pvc-pv.yaml Volume in a PersistentVolume with PersistentVolumeClaim
busybox-nfs-pvc-pv-sc.yaml Volume in a PersistentVolume with StorageClass and dynamic provisioning : (Please note that you first have to install NFS dynamic provisioner as noted above)
busybox-nfs-pvc-pv-csi.yaml Volume in a PersistentVolume with StorageClass and dynamic provisioning based on CSI NFS driver : (Please note that you first have to install CSI NFS driver as noted above)

Sample usage :

kubectl apply -f busybox-nfs-pvc-pv.yaml
kubectl delete -f busybox-nfs-pvc-pv.yaml

Then list the /var/nfs/exports folder content to view the nfs server storage content.

i.e. :

cat /var/nfs/exports/log.txt

should show the busybox-nfs example output

Additional configuration for the "Deploying Statefull Application to Kubernetes" course @PluralSight (to be published soon).

Add ingress support so that the users can access the demo application.

Finally, we’ll add the ingress support to minikube to access the demo.

minikube addons enable ingress

(WARNING : minikube 19.0 ingress support is bugged kubernetes/minikube#11121)

And we configure the name resolution so that the user can access the application with a domain name by first getting the node’s IP with :

minikube ip

and then, resolving the two domain names to that IP in the host’s file one for the frontend and one for the backend API. /etc/hosts

127.0.0.1	localhost
127.0.1.1	cursus
192.168.49.2 guestbook.frontend.minikube.local
192.168.49.2 guestbook.backend.minikube.local

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Alternatively you can use the minikube ingress-dns addon and resolve only the minikube ip in the hosts file.

How to build

The prebuilt image is pushed on Docker Hub in this repository : https://hub.docker.com/repository/docker/phico/nfs-server

If you want to modify the NFS server, the docker image source code is in docker-image folder.

About

NFS Server for testing NFS Storage with Kubernetes (minikube)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published