Last active
May 4, 2018 11:50
-
-
Save psturc/5c924030cb9c2a4589599af12ceaf5b7 to your computer and use it in GitHub Desktop.
Recreate PVs on NFS server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Login as admin user | |
oc login -u admin -p <password> > /dev/null | |
# List all Released pv names | |
for pv in `oc get pv | grep Released | awk '{print $1}'` ; | |
do | |
# Delete content of PV folders on NFS server | |
ssh 172.16.72.57 "echo ${pv} ; sudo rm -rf /exports/${pv}/*" | |
# Delete PV object | |
oc delete pv $pv | |
# Create new PV object from the template | |
pvsize=$(echo $pv | grep -o -E '[0-99]+' | head -1) | |
pvnumber=$(echo $pv | grep -o -E '[0-99]+' | tail -1) | |
eval "echo \"$(cat /home/hadmin/bin/pv-template.yml)\"" | oc create -f - | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: "v1" | |
kind: "PersistentVolume" | |
metadata: | |
name: "pv${pvsize}gi${pvnumber}" | |
spec: | |
capacity: | |
storage: "${pvsize}Gi" | |
accessModes: | |
- "ReadWriteOnce" | |
- "ReadWriteMany" | |
nfs: | |
server: "172.16.72.57" | |
path: "/exports/pv${pvsize}gi${pvnumber}" | |
persistentVolumeReclaimPolicy: "Retain" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment