Exercise
- Create a Pod with a single container based on mongo:5.0 and ensure it persists its data in an ephemeral volume
Hint: Mongo persists the data in it’s /data/db folder
-
Run a shell in the container and list the content of the /data/db folder
-
Get the unique identifier of the Pod
Hint: this can be retrieved in the property .metadata.uid
-
On which node is this Pod running
-
Run a shell on the node this Pod is running on and retrieve the content of the volume
Hint: it’s located in /var/lib/kubelet/pods/POD_ID/volumes/kubernetes.io~empty-dir/data
- Delete the Pod
Documentation
https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
Solution
- Create a Pod with a single container based on mongo:5.0 and ensure it persists its data in an ephemeral volume
kubectl run mongo --image=mongo:5.0 --dry-run=client -o yaml > pod.yaml
Add the volume section:
apiVersion: v1
kind: Pod
metadata:
labels:
run: mongo
name: mongo
spec:
containers:
- image: mongo:5.0
name: mongo
volumeMounts:
- name: data
mountPath: /data/db
volumes:
- name: data
emptyDir: {}
Create the Pod:
k apply -f pod.yaml
- Run a shell in the container and list the content of the /data/db folder
k exec mongo -- ls /data/db
- Get the unique identifier of the Pod
k get po mongo -o jsonpath={.metadata.uid}
- On which node is this Pod running
You can get the information with:
k get po mongo -o wide
- Run a shell on the node this Pod is running on and retrieve the content of the volume
Get the content of the following folder making sure to replace POD_ID with the unique identifier you get in question 3.
sudo ls /var/lib/kubelet/pods/POD_ID/volumes/kubernetes.io~empty-dir/data
- Delete the Pod
k delete po mongo