aelkz / kubernetes-nfs

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

Repository from Github https://github.comaelkz/kubernetes-nfsRepository from Github https://github.comaelkz/kubernetes-nfs

kubernetes-nfs

Project 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 NFS Server, run:

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

Deploying NFS Server Persistent

kubectl apply -f https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/nfs-pvc.yml -n $PROJECT_NAME
kubectl apply -f https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/nfs-server-deployment-persistent.yml -n $PROJECT_NAME
kubectl apply -f https://raw.githubusercontent.com/luszczynski/kubernetes-nfs/master/nfs-server-svc.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 need to 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

And create 100 PVs:

# Create kubernetes list
cat <<EOF > /tmp/persistent-volume-tmp.yml
apiVersion: v1
kind: List
items:
EOF

# 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

About

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