Last active
June 24, 2020 07:12
-
-
Save boina-n/874805fd9591cfbe2d960364447551ab to your computer and use it in GitHub Desktop.
How to extend PVC. #Kubernetes #Openshift
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
## 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