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