|
| 1 | +[[using-persistent-storage]] |
| 2 | +Using Persistent Storage |
| 3 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | + |
| 5 | +The purpose of this lab is to demonstrate how you can request storage |
| 6 | +from OpenShift and have it attach to your application. |
| 7 | + |
| 8 | +Containers, by design, are ephemeral. In short, if you want your application |
| 9 | +to store persistent data; you will need to attach to a backend storage system. |
| 10 | + |
| 11 | +In this Lab, we will be: |
| 12 | + |
| 13 | +* Deploying an application that takes uploads |
| 14 | +* Upload a File, and delete the pod |
| 15 | +* Attach persistant storage |
| 16 | +* Upload a File, and delete the pod |
| 17 | +
|
| 18 | +*NOTE:* Storage provisioning must be setup by the Operations Team before proceeding. |
| 19 | + |
| 20 | + |
| 21 | +*Step 1: Deploy Application* |
| 22 | + |
| 23 | +Create a project called `storage-UserName` and deploy the application |
| 24 | + |
| 25 | +.... |
| 26 | +oc new-project storage-UserName --description="My Storage-project" --display-name="Storage Project" |
| 27 | +oc new-app php~https://github.com/RedHatWorkshops/openshift-php-upload-demo |
| 28 | +.... |
| 29 | + |
| 30 | +Once the application is deployed expose the route |
| 31 | +.... |
| 32 | +$ oc get svc |
| 33 | +NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 34 | +openshift-php-upload-demo 172.30.212.62 <none> 8080/TCP 2m |
| 35 | + |
| 36 | +$ oc expose svc openshift-php-upload-demo |
| 37 | +route "openshift-php-upload-demo" exposed |
| 38 | +.... |
| 39 | + |
| 40 | +Visit your application; it should look like this |
| 41 | + |
| 42 | +image:images/upload-app.png[image] |
| 43 | + |
| 44 | +*Step 2: Test with ephemeral storage* |
| 45 | + |
| 46 | +Pick a file to upload and upload it to the app. Once uploaded you can view |
| 47 | +a list of file when you click `List Uploaded Files`. It should look something |
| 48 | +like this |
| 49 | + |
| 50 | +image:images/list-uploaded-files.png[image] |
| 51 | + |
| 52 | +You can see where the uploaded files are if you use `oc rsh`. They are uploaded |
| 53 | +under `/opt/app-root/src/uploaded` |
| 54 | + |
| 55 | +.... |
| 56 | +$ oc get pods |
| 57 | +NAME READY STATUS RESTARTS AGE |
| 58 | +openshift-php-upload-demo-1-build 0/1 Completed 0 10m |
| 59 | +openshift-php-upload-demo-1-rdktr 1/1 Running 0 5m |
| 60 | +
|
| 61 | +$ oc rsh openshift-php-upload-demo-1-rdktr |
| 62 | +sh-4.2$ ls -1 /opt/app-root/src/uploaded |
| 63 | +shadowman.png |
| 64 | +sh-4.2$ exit |
| 65 | +.... |
| 66 | + |
| 67 | +Delete this pod. |
| 68 | + |
| 69 | +.... |
| 70 | +$ oc delete pod openshift-php-upload-demo-1-rdktr |
| 71 | +pod "openshift-php-upload-demo-1-rdktr" deleted |
| 72 | +.... |
| 73 | + |
| 74 | +Now login to your new pod that got spun up. Your data is gone! |
| 75 | +.... |
| 76 | +$ oc get pods |
| 77 | +NAME READY STATUS RESTARTS AGE |
| 78 | +openshift-php-upload-demo-1-build 0/1 Completed 0 13m |
| 79 | +openshift-php-upload-demo-1-wnv4r 1/1 Running 0 38s |
| 80 | + |
| 81 | +$ oc rsh openshift-php-upload-demo-1-wnv4r |
| 82 | +sh-4.2$ ls -1 /opt/app-root/src/uploaded |
| 83 | +sh-4.2$ exit |
| 84 | +.... |
| 85 | + |
| 86 | + |
| 87 | +*Step 3: Requesting Storage* |
| 88 | + |
| 89 | +In OpenShift, Storage is abstracted out to where one simply "requests" storage |
| 90 | +and it's up to the backend adminsitrator to provide the solution |
| 91 | + |
| 92 | +On the webconsole on the left side navigation click on "Storage". It will bing |
| 93 | +you to the storage overview page. |
| 94 | + |
| 95 | +image:images/storage-overview.png[image] |
| 96 | + |
| 97 | +On the right hand side; click the "Create Storage" button. This will take you |
| 98 | +to the "Create Storage" page. |
| 99 | + |
| 100 | +image:images/create-storage.png[image] |
| 101 | + |
| 102 | +Here you need to enter the following |
| 103 | + |
| 104 | +---- |
| 105 | +* Storage Class: <provided by your instructor> |
| 106 | +* Name: myclaim |
| 107 | +* Access Mode: Shared Access (RWX) |
| 108 | +* Size: 1 GiB |
| 109 | +---- |
| 110 | + |
| 111 | +The `Storage Class` will be given to you by your instructor. The `Name` must be |
| 112 | +unique to the project namespace. The `Access Mode` means "how many apps can access |
| 113 | +this storage". For block storage you'd choose `Singe User (RWO)`; in this instance |
| 114 | +we are choosing `Shared Access (RWX)` (for File based storage like NFS). The `Size` |
| 115 | +is set to `1 GB` just for testing. |
| 116 | + |
| 117 | +Once you click on "Create" it'll go from a `Pending` stage to `Bound`. You can see |
| 118 | +this on the command-line as well by checking your `pvc` (Which stands for Persistant |
| 119 | +Volume Claim) |
| 120 | + |
| 121 | +.... |
| 122 | +$ oc get pvc |
| 123 | +NAME STATUS VOLUME CAPACITY ACCESSMODES AGE |
| 124 | +myclaim Bound pvc-071ee3ef-86d2-11e7-aec4-52540019c877 1Gi RWX 27s |
| 125 | +.... |
| 126 | + |
| 127 | +Get yourself familair with the configuration |
| 128 | +.... |
| 129 | +$ oc get pvc myclaim -o yaml |
| 130 | +apiVersion: v1 |
| 131 | +kind: PersistentVolumeClaim |
| 132 | +metadata: |
| 133 | + annotations: |
| 134 | + pv.kubernetes.io/bind-completed: "yes" |
| 135 | + pv.kubernetes.io/bound-by-controller: "yes" |
| 136 | + volume.beta.kubernetes.io/storage-class: glusterfs-storage |
| 137 | + volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/glusterfs |
| 138 | + creationTimestamp: 2017-08-22T00:37:07Z |
| 139 | + name: myclaim |
| 140 | + namespace: storage-UserName |
| 141 | + resourceVersion: "48898" |
| 142 | + selfLink: /api/v1/namespaces/testing-user00/persistentvolumeclaims/myclaim |
| 143 | + uid: 071ee3ef-86d2-11e7-aec4-52540019c877 |
| 144 | +spec: |
| 145 | + accessModes: |
| 146 | + - ReadWriteMany |
| 147 | + resources: |
| 148 | + requests: |
| 149 | + storage: 1Gi |
| 150 | + volumeName: pvc-071ee3ef-86d2-11e7-aec4-52540019c877 |
| 151 | +status: |
| 152 | + accessModes: |
| 153 | + - ReadWriteMany |
| 154 | + capacity: |
| 155 | + storage: 1Gi |
| 156 | + phase: Bound |
| 157 | +.... |
| 158 | + |
| 159 | +We will now bind this storage to the application's path of where it is |
| 160 | +storing the files. This is under `/opt/app-root/src/uploaded`. You need |
| 161 | +to add the volume to the `deploymentConfig` of `openshift-php-upload-demo`. |
| 162 | + |
| 163 | +.... |
| 164 | +$ oc volume dc/openshift-php-upload-demo --add -t pvc --claim-name=myclaim --mount-path=/opt/app-root/src/uploaded |
| 165 | +info: Generated volume name: volume-c7jtb |
| 166 | +deploymentconfig "openshift-php-upload-demo" updated |
| 167 | +.... |
| 168 | + |
| 169 | +*Step 3: Testing Configuration* |
| 170 | + |
| 171 | +This will trigger a new deployment. Login to your pod to see the mount. |
| 172 | + |
| 173 | +.... |
| 174 | +$ oc get pods |
| 175 | +NAME READY STATUS RESTARTS AGE |
| 176 | +openshift-php-upload-demo-1-build 0/1 Completed 0 1h |
| 177 | +openshift-php-upload-demo-8-16dzg 1/1 Running 0 1m |
| 178 | +
|
| 179 | +$ oc rsh openshift-php-upload-demo-8-16dzg |
| 180 | +sh-4.2$ df -h /opt/app-root/src/uploaded/ |
| 181 | +Filesystem Size Used Avail Use% Mounted on |
| 182 | +172.16.1.11:vol_464dc941ae641d2693b1382cc221a0b5 1016M 33M 983M 4% /opt/app-root/src/uploaded |
| 183 | +.... |
| 184 | + |
| 185 | +Upload a file like before. Once uploaded; delete the pod |
| 186 | + |
| 187 | +.... |
| 188 | +$ oc get pods |
| 189 | +NAME READY STATUS RESTARTS AGE |
| 190 | +openshift-php-upload-demo-1-build 0/1 Completed 0 1h |
| 191 | +openshift-php-upload-demo-8-16dzg 1/1 Running 0 2m |
| 192 | +
|
| 193 | +$ oc delete pod openshift-php-upload-demo-8-16dzg |
| 194 | +pod "openshift-php-upload-demo-8-16dzg" deleted |
| 195 | +.... |
| 196 | + |
| 197 | +Log into the newly spunup pod and verify that your file is still there! |
| 198 | + |
| 199 | +.... |
| 200 | +$ oc get pods |
| 201 | +NAME READY STATUS RESTARTS AGE |
| 202 | +openshift-php-upload-demo-1-build 0/1 Completed 0 1h |
| 203 | +openshift-php-upload-demo-8-4brh0 1/1 Running 0 58s |
| 204 | +
|
| 205 | +$ oc rsh openshift-php-upload-demo-8-4brh0 |
| 206 | +sh-4.2$ ls -1 /opt/app-root/src/uploaded/ |
| 207 | +shadowman.png |
| 208 | +.... |
| 209 | + |
| 210 | +[[summary]] |
| 211 | +Summary |
| 212 | +^^^^^^^ |
| 213 | + |
| 214 | +In this lab you learned how to request, attach, and test persistant storage. |
| 215 | + |
| 216 | +link:0_toc.adoc[Table Of Contents] |
0 commit comments