- Lab
- A Cloud Guru
CKA Practice Exam: Part 2
Managing storage is a challenge for most organizations. Kubernetes allows you to create persistent storage so the data is not lost when a pod is moved or deleted. In this portion of the practice exam, you will demonstrate your knowledge of `PersistentVolumes` and `PersistentVolumeClaims` in order to ensure data integrity. This will simulate a question you may see on the Certified Kubernetes Administrator (CKA) exam.
Path Info
Table of Contents
-
Challenge
Create the `PersistentVolumeClaim`.
- Use the following command to check if there is already a 'web' namespace:
kubectl get ns kubectl get pv
- Use the following command to create a
PersistentVolumeClaim
work from scratch or use a Kubernetes template file. Search the documentation :
vi data-pvc.yaml #copy and paste from docs
- Update the file
data-pvc.yaml
with the following details:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: data-pvc namespace: web spec: storageClassName: local-storage accessModes: - ReadWriteOnce resources: requests: storage: 256Mi
- Use the following command to create the PVC:
kubectl apply -f data-pvc.yaml
-
Challenge
Create a pod mounting the volume and write data to the volume.
- Use the following command to create the YAML for a busybox pod:
kubectl run data-pod --image=busybox:1.28 --restart=Never -o yaml --dry-run -- /bin/sh -c 'sleep 3600' > data-pod.yaml
- Use the following command to edit the
data-pod.yaml
file:
vi data-pod.yaml
- Update the
data-pod.yaml
file as below:
apiVersion: v1 kind: Pod metadata: name: data-pod namespace: web spec: containers: - args: - /bin/sh - -c - sleep 3600 image: busybox:1.28 name: data-pod resources: {} volumeMounts: - name: temp-data mountPath: /tmp/data dnsPolicy: ClusterFirst restartPolicy: Never volumes: - name: temp-data persistentVolumeClaim: claimName: data-pvc
- Use the following command to create the pod:
kubectl apply -f data-pod.yaml
- Use the following command to connect to the pod:
kubectl exec -it data-pod -n web -- sh
- Use the following commands to confirm the environmant and to copy the contents of the
etc/passwd
file to/tmp/data
:
# ls -la /etc/passwd # ls -la /tmp/data/ # cp /etc/passwd /tmp/data/passwd
- Use the following command to list the contents of
/tmp/data
:
# ls /tmp/data/
-
Challenge
Delete the pod and create a new pod and view volume data.
-
Use the following command to delete the pod:
kubectl delete po data-pod -n web
-
Use the following command to modify the pod YAML:
vi data-pod.yaml
-
Change the following line in the
data-pod.yaml
file:name: data-pod2
-
Use the following command to create a new pod:
kubectl apply -f data-pod.yaml
-
Use the following command to connect to the pod and view the contents of the volume:
kubectl exec -it data-pod2 -n web -- sh # ls /tmp/data
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.