Skip to content

Instantly share code, notes, and snippets.

@boina-n
Last active June 24, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boina-n/874805fd9591cfbe2d960364447551ab to your computer and use it in GitHub Desktop.
Save boina-n/874805fd9591cfbe2d960364447551ab to your computer and use it in GitHub Desktop.
How to extend PVC. #Kubernetes #Openshift
## How to extend a PV:
pvcname=pvc60
volumename=volume60
mountpath=/opt/app-root/src/mount60
# Deploy a test app
oc new-app --template=openshift/httpd-example --name=app01
# Create a PVC
cat << EOF | oc create -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: $pvcname
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 4Gi
storageClassName: block-default-storage-class
volumeMode: Filesystem
EOF
# mount volume through the console:
Action > Add storage > use existing claim
Mountpath : $mountpath
Save
# create a test file in the volume
oc get pods
podname=app01-4-47pkc
oc exec $podname -- bash -c "echo test > $mountpath/webpage.html »
# verify the file before expanding the size
oc get route
route=httpd-example
oc patch route/$route -p '{"spec":{"tls":{"termination":"edge"}}}'
route=$(oc get route $route -o=jsonpath='{.spec.host}')
curl -s -L https://$route/mount60/webpage.html
>> test
oc exec $podname -- df -h $mountpath
# Scale down the deployment to 0 in order to resize the volume
#note the replica number to reset it as it was.
oc get dc
oc scale dc/httpd-example --replicas=0
# Expand hth volume
oc get pvc
oc patch pvc $pvcname --type=merge -p '{"spec":{"resources":{"requests":{"storage": "5Gi"}}}}’
# Scale up the application in order for the pvc to increase
oc scale dc/httpd-example --replicas=1
# watch pvc change size
watch oc get pvc
#Verify the data is still on the volume after expansion
curl -s -L https://$route/mount60/webpage.html
>> test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment