Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 303c138

Browse files
Rojan JoseRojan Jose
authored andcommitted
lab1 instructions
1 parent 8bed33f commit 303c138

File tree

4 files changed

+163
-75
lines changed

4 files changed

+163
-75
lines changed

workshop/Lab1/README.md

Lines changed: 163 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ NAME CAPACITY ACCESS MODES RECLAIM POL
5454
guestbook-primary-pv 10Gi RWO Retain Available manual 13s
5555
```
5656

57+
Next
5758
PVC yaml:
5859
```
5960
apiVersion: v1
@@ -82,136 +83,223 @@ guestbook-local-pvc Bound guestbook-local-pv 10Gi
8283

8384
## Guestbook application using storage
8485

85-
The application is the [Guestbook App](https://github.com/IBM/guestbook-nodejs), which is a sample multi-tier web application.
86+
The application is the [Guestbook App](https://github.com/IBM/guestbook-nodejs), which is a simple multi-tier web application built using the loopback framework.
8687

88+
Change to the guestbook application source directory:
8789

88-
Build the image
89-
Misc: (building v3 image)
9090
```
91-
docker build -t rojanjose/guestbook:v31 .
92-
docker push rojanjose/guestbook:v31
93-
https://hub.docker.com/repository/docker/rojanjose/guestbook/tags?page=1
91+
cd $HOME/guestbook-nodejs/src
9492
```
93+
Review the source `common/models/entry.js`. The application uses storage allocated using `hostPath` to store data cache in the file `data/cache.txt`. The file `logs/debug.txt` records debug messages and is provisioned via the `emptyDir` storage type.
9594

95+
```source
96+
module.exports = function(Entry) {
97+
98+
Entry.greet = function(msg, cb) {
99+
100+
// console.log("testing " + msg);
101+
fs.appendFile('logs/debug.txt', "Recevied message: "+ msg +"\n", function (err) {
102+
if (err) throw err;
103+
console.log('Debug stagement printed');
104+
});
105+
106+
fs.appendFile('data/cache.txt', msg+"\n", function (err) {
107+
if (err) throw err;
108+
console.log('Saved in cache!');
109+
});
110+
111+
...
112+
```
113+
114+
Run the commands listed below to build the guestbook image and copy into docker hub registry:
96115

97-
Main.go file:
98-
Line 186
99116
```
100-
//Setip data file
101-
f, err := os.OpenFile("data/datafile.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
102-
117+
cd $HOME/guestbook-nodejs/src
118+
docker build -t $DOCKERUSER/guestbook-nodejs:storage .
119+
export DOCKERUSER=rojanjose
120+
docker login -u DOCKERUSER
121+
docker push $DOCKERUSER/guestbook-nodejs:storage
103122
```
104123

105-
Deployment yaml:
124+
Review the deployment yaml file `guestbook-deplopyment.yaml` prior to deploying the application into the cluster.
125+
126+
```
127+
cd $HOME/storage/lab1
128+
cat guestbook-deplopyment.yaml
129+
```
130+
131+
The section `spec.volumes` lists `hostPath` and `emptyDir` volumes. The section `spec.containers.volumeMounts` lists the mount paths that the application uses to write in the volumes.
132+
106133
```
107134
apiVersion: apps/v1
108135
kind: Deployment
109-
...
136+
metadata:
137+
name: guestbook-v1
138+
labels:
139+
app: guestbook
140+
...
110141
spec:
111142
containers:
112143
- name: guestbook
113-
image: rojanjose/guestbook:v31
144+
image: rojanjose/guestbook-nodejs:storage
145+
imagePullPolicy: Always
114146
ports:
115147
- name: http-server
116148
containerPort: 3000
117149
volumeMounts:
118-
- name: guestbook-data-volume
119-
mountPath: /app/data
150+
- name: guestbook-primary-volume
151+
mountPath: /home/node/app/data
152+
- name: guestbook-secondary-volume
153+
mountPath: /home/node/app/logs
120154
volumes:
121-
- name: guestbook-data-volume
155+
- name: guestbook-primary-volume
122156
persistentVolumeClaim:
123-
claimName: guestbook-local-pvc
157+
claimName: guestbook-primary-pvc
158+
- name: guestbook-secondary-volume
159+
emptyDir: {}
160+
161+
162+
...
124163
```
125164

126165
Deploy Guestbook application:
127166

128167
```
129-
kubectl create -f guestbook-deployment.yaml
168+
kubectl create -f guestbook-deployment.yaml
130169
deployment.apps/guestbook-v1 created
131-
❯ kubectl get pods
170+
171+
kubectl get pods
132172
NAME READY STATUS RESTARTS AGE
133173
guestbook-v1-6f55cb54c5-jb89d 1/1 Running 0 14s
134-
❯ kubectl create -f guestbook-service.yaml
174+
175+
kubectl create -f guestbook-service.yaml
135176
service/guestbook created
136177
```
137178

138-
Load data:
139-
140-
![Guestbook images](images/guestbook-local-data.png)
141-
142-
143-
Log into the pod:
179+
Find the URL for the guestbook application by joining the worker node external IP and service node port.
144180

145181
```
146-
kubectl exec -it guestbook-v1-6f55cb54c5-jb89d -- busybox sh
182+
HOSTNAME=`ibmcloud ks workers --cluster $CLUSTERNAME | grep Ready | head -n 1 | awk '{print $2}'`
183+
SERVICEPORT=`kubectl get svc guestbook -o=jsonpath='{.spec.ports[0].nodePort}'`
184+
echo "http://$HOSTNAME:$SERVICEPORT"
185+
```
147186

187+
Open the URL in a browser and create guest book entries.
148188

149-
BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
150-
Enter 'help' for a list of built-in commands.
189+
![Guestbook entries](images/lab1-guestbook-entries.png)
151190

152-
/app # cat data/datafile.txt
153-
2020/11/04 05:14:29 Logging guestbook data:
154-
2020/11/04 05:20:14 One
155-
2020/11/04 05:20:17 Two
156-
2020/11/04 05:20:20 Three
191+
Log into the pod:
157192

158-
/app # df -ah
159-
Filesystem Size Used Available Use% Mounted on
160-
overlay 97.9G 1.4G 91.5G 2% /
161-
proc 0 0 0 0% /proc
162-
tmpfs 64.0M 0 64.0M 0% /dev
163-
devpts 0 0 0 0% /dev/pts
164-
cgroup 0 0 0 0% /sys/fs/cgroup/perf_event
165-
...
193+
```
194+
kubectl exec -it guestbook-v1-6f55cb54c5-jb89d bash
195+
196+
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
197+
198+
root@guestbook-v1-6f55cb54c5-jb89d:/home/node/app# ls -al
199+
total 256
200+
drwxr-xr-x 1 root root 4096 Nov 11 23:40 .
201+
drwxr-xr-x 1 node node 4096 Nov 11 23:20 ..
202+
-rw-r--r-- 1 root root 12 Oct 29 21:00 .dockerignore
203+
-rw-r--r-- 1 root root 288 Oct 29 21:00 .editorconfig
204+
-rw-r--r-- 1 root root 8 Oct 29 21:00 .eslintignore
205+
-rw-r--r-- 1 root root 27 Oct 29 21:00 .eslintrc
206+
-rw-r--r-- 1 root root 151 Oct 29 21:00 .gitignore
207+
-rw-r--r-- 1 root root 30 Oct 29 21:00 .yo-rc.json
208+
-rw-r--r-- 1 root root 105 Oct 29 21:00 Dockerfile
209+
drwxr-xr-x 2 root root 4096 Nov 11 03:40 client
210+
drwxr-xr-x 3 root root 4096 Nov 10 23:04 common
211+
drwxr-xr-x 2 root root 4096 Nov 11 23:16 data
212+
drwxrwxrwx 2 root root 4096 Nov 11 23:44 logs
213+
drwxr-xr-x 439 root root 16384 Nov 11 23:20 node_modules
214+
-rw-r--r-- 1 root root 176643 Nov 11 23:20 package-lock.json
215+
-rw-r--r-- 1 root root 830 Nov 11 23:20 package.json
216+
drwxr-xr-x 3 root root 4096 Nov 10 23:04 server
217+
218+
root@guestbook-v1-6f55cb54c5-jb89d:/home/node/app# cat data/cache.txt
219+
Hello Kubernetes!
220+
Hola Kubernetes!
221+
Zdravstvuyte Kubernetes!
222+
Nǐn hǎo Kubernetes!
223+
Goedendag Kubernetes!
224+
225+
root@guestbook-v1-6f55cb54c5-jb89d:/home/node/app# cat logs/debug.txt
226+
Recevied message: Hello Kubernetes!
227+
Recevied message: Hola Kubernetes!
228+
Recevied message: Zdravstvuyte Kubernetes!
229+
Recevied message: Nǐn hǎo Kubernetes!
230+
Recevied message: Goedendag Kubernetes!
231+
232+
233+
root@guestbook-v1-6f55cb54c5-jb89d:/home/node/app# df -h
234+
Filesystem Size Used Avail Use% Mounted on
235+
overlay 98G 3.5G 90G 4% /
236+
tmpfs 64M 0 64M 0% /dev
237+
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
238+
/dev/mapper/docker_data 98G 3.5G 90G 4% /etc/hosts
239+
shm 64M 0 64M 0% /dev/shm
240+
/dev/xvda2 25G 3.6G 20G 16% /home/node/app/data
241+
tmpfs 7.9G 16K 7.9G 1% /run/secrets/kubernetes.io/serviceaccount
242+
tmpfs 7.9G 0 7.9G 0% /proc/acpi
243+
tmpfs 7.9G 0 7.9G 0% /proc/scsi
244+
tmpfs 7.9G 0 7.9G 0% /sys/firmware
166245
167-
/dev/xvda2 24.2G 2.2G 20.8G 9% /app/data
168-
...
169-
tmpfs 7.8G 0 7.8G 0% /sys/firmware
170246
```
171247

172-
Kill the pod:
248+
Kill the pod to see the impact of deleting the pod on data.
173249

174250
```
175251
kubectl get pods
176252
NAME READY STATUS RESTARTS AGE
177253
guestbook-v1-6f55cb54c5-jb89d 1/1 Running 0 12m
178-
179-
180-
❯ kubectl delete pod guestbook-v1-6f55cb54c5-jb89d
254+
255+
kubectl delete pod guestbook-v1-6f55cb54c5-jb89d
181256
pod "guestbook-v1-6f55cb54c5-jb89d" deleted
182-
❯ kubectl get pods
257+
258+
kubectl get pods
183259
NAME READY STATUS RESTARTS AGE
184-
guestbook-v1-6f55cb54c5-gctwt 1/1 Running 0 11s
260+
guestbook-v1-5cbc445dc9-sx58j 1/1 Running 0 86s
185261
```
186262

187-
![Guestbook images](images/guestbook-local-data-deleted.png)
263+
![Guestbook delete data](images/lab1-guestbook-data-deleted.png)
188264

189-
Enter data:
190-
![Guestbook images](images/guestbook-local-data-reload.png)
265+
Enter new data:
266+
![Guestbook reload](images/lab1-guestbook-data-reload.png)
191267

268+
Log into the pod to view the state of the data.
192269

193270
```
194-
kubectl exec -it guestbook-v1-6f55cb54c5-gctwt -- busybox sh
271+
kubectl get pods
272+
NAME READY STATUS RESTARTS AGE
273+
guestbook-v1-5cbc445dc9-sx58j 1/1 Running 0 86s
274+
275+
kubectl exec -it guestbook-v1-5cbc445dc9-sx58j bash
276+
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
277+
278+
root@guestbook-v1-5cbc445dc9-sx58j:/home/node/app# cat data/cache.txt
279+
Hello Kubernetes!
280+
Hola Kubernetes!
281+
Zdravstvuyte Kubernetes!
282+
Nǐn hǎo Kubernetes!
283+
Goedendag Kubernetes!
284+
Bye Kubernetes!
285+
Aloha Kubernetes!
286+
Ciao Kubernetes!
287+
Sayonara Kubernetes!
288+
289+
root@guestbook-v1-5cbc445dc9-sx58j:/home/node/app# cat logs/debug.txt
290+
Recevied message: Bye Kubernetes!
291+
Recevied message: Aloha Kubernetes!
292+
Recevied message: Ciao Kubernetes!
293+
Recevied message: Sayonara Kubernetes!
294+
root@guestbook-v1-5cbc445dc9-sx58j:/home/node/app#
295+
```
195296

297+
This shows that the storage type `emptyDir` loose data on a pod restart where as `hostPath` data lives until the worker node or cluster is deleted.
196298

197-
BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
198-
Enter 'help' for a list of built-in commands.
199299

200-
/app # ls -alt
201-
total 8972
202-
drwxr-xr-x 1 root root 4096 Nov 4 05:27 .
203-
drwxr-xr-x 1 root root 4096 Nov 4 05:27 ..
204-
drwxr-xr-x 2 root root 4096 Nov 4 05:14 data
205-
drwxr-xr-x 1 root root 4096 Nov 4 05:12 public
206-
-rwxr-xr-x 1 root root 9167339 Nov 4 05:12 guestbook
207-
/app # cat data/datafile.txt
208-
2020/11/04 05:14:29 Logging guestbook data:
209-
2020/11/04 05:20:14 One
210-
2020/11/04 05:20:17 Two
211-
2020/11/04 05:20:20 Three
212-
2020/11/04 05:27:20 Logging guestbook data:
213-
2020/11/04 05:32:04 Four
214-
2020/11/04 05:32:07 Five
215-
2020/11/04 05:32:08 Six
216-
```
300+
## Clean up
217301

302+
```
303+
cd $HOME/guestbook-config/storage/lab1
304+
kubectl delete -f .
305+
```
107 KB
Loading
182 KB
Loading
198 KB
Loading

0 commit comments

Comments
 (0)