Skip to content

Project to create a NFS Server container on top of Kubernetes/Openshift

Notifications You must be signed in to change notification settings

luszczynski/kubernetes-nfs

Repository files navigation

Kubernetes/OpenShift NFS Server

The goal of this project is to create a NFS Server container on top of Kubernetes/OpenShift. This is helpful when we need a quick RWX volume. I use it for demo only.

  • ✓ Install NFS on container

  • ✓ Generate PVs using bash

  • ✓ Create persistent option

  • ❏ Use NFS provisioner

Pre-req

Create project and set permission

export PROJECT_NAME=nfs-server

# For OpenShift
oc new-project $PROJECT_NAME
oc adm policy add-scc-to-user privileged -z default -n $PROJECT_NAME

# For Kubernetes
kubectl create namespace $PROJECT_NAME

Installing

Deploying NFS Server Ephemeral

To deploy a NFS Server ephemeral (using emptyDir), run:

kubectl apply \
  -f https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/nfs-server-ephemeral.yml \
  -n $PROJECT_NAME

Deploying NFS Server Persistent

To deploy a NFS Server persistent (using PV), run:

# Create pvc for NFS
kubectl apply \
  -f https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/nfs-server-persistent.yml \
  -n $PROJECT_NAME

Creating PVs for the cluster

We’ll need the ClusterIp of our NFS Server to use it in our PVs. We can get it by running the following command:

NFS_CLUSTER_IP=$(kubectl -n $PROJECT_NAME get svc/nfs-server-alpine -o=jsonpath='{.spec.clusterIP}')

# Now make sure the var NFS_CLUSTER_IP contains the cluster ip:
echo $NFS_CLUSTER_IP

# Now install all PVs by running:
curl https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/persistent-volumes.yml | sed "s/REPLACEME/$NFS_CLUSTER_IP/g"  | kubectl apply -f -

OPTIONAL

You can create the PVs file in your local machine:

# Create 100 PVs 100Gi
for i in {0..100}; do

cat <<EOF >> /tmp/persistent-volume-tmp.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv$i
spec:
  capacity:
    storage: 100Gi
  nfs:
    server: $NFS_CLUSTER_IP
    path: /pv$i
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Recycle
  volumeMode: Filesystem
---
EOF

done

# Create all PVs
kubectl apply -f /tmp/persistent-volume-tmp.yml

Clean up

Removing NFS Server

kubectl delete deploy/nfs-server-alpine -n $PROJECT_NAME
kubectl delete svc/nfs-server-alpine -n $PROJECT_NAME
kubectl delete pvc/nfs-pvc -n $PROJECT_NAME

Removing PVs

for i in {0..100}; do
  kubectl delete pv/pv$i
done

Releases

No releases published

Packages

No packages published