Skip to content

Commit 41daed9

Browse files
authored
Update state-persistence.md
1 parent ebe1843 commit 41daed9

File tree

1 file changed

+177
-7
lines changed

1 file changed

+177
-7
lines changed

state-persistence.md

+177-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,183 @@
77

88
## Questions
99

10-
### TBD
1110

12-
<details><summary></summary>
13-
<p>
11+
<details><summary>List Persistent Volumes in the cluster</summary>
12+
<p>
1413

15-
```
14+
```
15+
kubectl get pv
16+
```
17+
</p>
18+
</details>
19+
20+
21+
<details><summary>Create a hostPath PersistentVolume named task-pv-volume with storage 10Gi, access modes ReadWriteOnce, storageClassName manual, and volume at /mnt/data and verify</summary>
22+
<p>
23+
24+
```
25+
// task-pv-volume.yaml
26+
27+
apiVersion: v1
28+
kind: PersistentVolume
29+
metadata:
30+
name: task-pv-volume
31+
labels:
32+
type: local
33+
spec:
34+
storageClassName: manual
35+
capacity:
36+
storage: 10Gi
37+
accessModes:
38+
- ReadWriteOnce
39+
hostPath:
40+
path: "/mnt/data"
41+
42+
kubectl create -f task-pv-volume.yaml
43+
44+
kubectl get pv
45+
```
46+
</p>
47+
</details>
48+
49+
50+
51+
<details><summary>Create a PersistentVolumeClaim of at least 3Gi storage and access mode ReadWriteOnce and verify status is Bound</summary>
52+
<p>
53+
54+
```
55+
// task-pv-claim.yaml
56+
57+
apiVersion: v1
58+
kind: PersistentVolumeClaim
59+
metadata:
60+
name: task-pv-claim
61+
spec:
62+
storageClassName: manual
63+
accessModes:
64+
- ReadWriteOnce
65+
resources:
66+
requests:
67+
storage: 3Gi
68+
69+
kubectl create -f task-pv-claim.yaml
70+
71+
kubectl get pvc
72+
```
73+
</p>
74+
</details>
75+
76+
77+
<details><summary>Delete persistent volume and PersistentVolumeClaim we just created</summary>
78+
<p>
79+
80+
```
81+
kubectl delete pvc task-pv-claim
82+
kubectl delete pv task-pv-volume
83+
```
84+
</p>
85+
</details>
86+
87+
88+
<details><summary>Create a Pod with an image Redis and configure a volume that lasts for the lifetime of the Pod</summary>
89+
<p>
90+
91+
```
92+
// emptyDir is the volume that lasts for the life of the pod
93+
94+
apiVersion: v1
95+
kind: Pod
96+
metadata:
97+
name: redis
98+
spec:
99+
containers:
100+
- name: redis
101+
image: redis
102+
volumeMounts:
103+
- name: redis-storage
104+
mountPath: /data/redis
105+
volumes:
106+
- name: redis-storage
107+
emptyDir: {}
108+
109+
kubectl create -f redis-storage.yaml
110+
```
111+
</p>
112+
</details>
113+
114+
115+
<details><summary>Exec into the above pod and create a file named file.txt with the text ‘This is called the file’ in the path /data/redis and open another tab and exec again with the same pod and verifies file exist in the same path.</summary>
116+
<p>
16117

17-
```
18-
</p>
19-
</details>
118+
```
119+
// first terminal
120+
kubectl exec -it redis-storage /bin/sh
121+
cd /data/redis
122+
echo 'This is called the file' > file.txt
123+
124+
//open another tab
125+
kubectl exec -it redis-storage /bin/sh
126+
cat /data/redis/file.txt
127+
```
128+
</p>
129+
</details>
130+
131+
132+
<details><summary>Delete the above pod and create again from the same yaml file and verifies there is no file.txt in the path /data/redis.</summary>
133+
<p>
134+
135+
```
136+
kubectl delete pod redis
137+
138+
kubectl create -f redis-storage.yaml
139+
kubectl exec -it redis-storage /bin/sh
140+
cat /data/redis/file.txt // file doesn't exist
141+
```
142+
</p>
143+
</details>
144+
145+
146+
<details><summary>Create PersistentVolume named task-pv-volume with storage 10Gi, access modes ReadWriteOnce, storageClassName manual, and volume at /mnt/data and Create a PersistentVolumeClaim of at least 3Gi storage and access mode ReadWriteOnce and verify status is Bound</summary>
147+
<p>
148+
149+
```
150+
kubectl create -f task-pv-volume.yaml
151+
kubectl create -f task-pv-claim.yaml
152+
153+
kubectl get pv
154+
kubectl get pvc
155+
```
156+
</p>
157+
</details>
158+
159+
160+
<details><summary> Create an nginx pod with containerPort 80 and with a PersistentVolumeClaim task-pv-claim and has a mouth path "/usr/share/nginx/html"</summary>
161+
<p>
162+
163+
```
164+
// task-pv-pod.yaml
165+
166+
apiVersion: v1
167+
kind: Pod
168+
metadata:
169+
name: task-pv-pod
170+
spec:
171+
volumes:
172+
- name: task-pv-storage
173+
persistentVolumeClaim:
174+
claimName: task-pv-claim
175+
containers:
176+
- name: task-pv-container
177+
image: nginx
178+
ports:
179+
- containerPort: 80
180+
name: "http-server"
181+
volumeMounts:
182+
- mountPath: "/usr/share/nginx/html"
183+
name: task-pv-storage
184+
185+
kubectl create -f task-pv-pod.yaml
186+
```
187+
</p>
188+
</details>
189+

0 commit comments

Comments
 (0)