Skip to content

Commit eab0243

Browse files
committed
added lab
1 parent 8ebef0d commit eab0243

7 files changed

+217
-0
lines changed

0_Table_of_Contents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Lab 14. [Code Promotion Across Environments](12_Code_Promotion_Across_Environments.md)
1919
* Lab 15. [Changing code on the fly](18_Changing_code_on_the_fly.md)
2020
* Lab 16. [Creating a CI/CD Pipeline](19._Creating_a_Pipeline.md)
21+
* Lab 17. [Persistent Storage](13_Using_Persistent_Storage.adoc)
2122
### END OF GUIDED LABS
2223
Now that you know the basics, please explore the platform. Here are a few suggestions, but you may try with your own code and applications.
2324

13_Using_Persistent_Storage.adoc

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
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]

images/create-storage.png

45.7 KB
Loading

images/list-uploaded-files.png

13.5 KB
Loading

images/storage-overview.png

39.1 KB
Loading

images/upload-app.png

27.7 KB
Loading

list-uploaded-files.png

13.5 KB
Loading

0 commit comments

Comments
 (0)