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
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
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
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 -
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