Skip to content

Instantly share code, notes, and snippets.

@justindav1s
Last active January 25, 2020 13:38
Show Gist options
  • Save justindav1s/7e96049b7baf1d0d4caffaf29498f2b2 to your computer and use it in GitHub Desktop.
Save justindav1s/7e96049b7baf1d0d4caffaf29498f2b2 to your computer and use it in GitHub Desktop.
Create NFS Persistent Volumes
#!/usr/bin/env bash
PV_STUB="nfspv000"
OCP="api.ocp4:6443"
NFS_HOST=192.168.10.25
oc login https://${OCP}
for i in {1..30}; do
PV_NAME=$PV_STUB$i
echo Setting up $PV_NAME
cat <<EOF > ${PV_NAME}.yml
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: "${PV_NAME}"
labels:
type: nfs
spec:
capacity:
storage: "100Gi"
accessModes:
- "ReadWriteOnce"
- "ReadWriteMany"
nfs:
path: "/export/${PV_NAME}"
server: "${NFS_HOST}"
persistentVolumeReclaimPolicy: "Recycle"
EOF
oc delete pv $PV_NAME
ssh root@${NFS_HOST} rm -rf /export/$PV_NAME
ssh root@${NFS_HOST} mkdir /export/$PV_NAME
ssh root@${NFS_HOST} chmod -R 777 /export/$PV_NAME
ssh root@${NFS_HOST} chown -R nfsnobody:nfsnobody /export/$PV_NAME
ssh root@${NFS_HOST} "echo /export/$PV_NAME *\(rw,sync,no_wdelay,no_root_squash,insecure,fsid=0\) >> /etc/exports.d/openshift-uservols.exports"
oc create -f $PV_NAME.yml
rm -rf $PV_NAME.yml
done
systemctl restart nfs
oc get pv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment