CKA Practice Exam: Part 2

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the `PersistentVolumeClaim`.
  1. Use the following command to check if there is already a ‘web’ namespace:

    kubectl get ns
    kubectl get pv
  2. 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
  3. 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
  1. Use the following command to create the PVC:
    kubectl apply -f data-pvc.yaml
Create a pod mounting the volume and write data to the volume.
  1. 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
  1. Use the following command to edit the data-pod.yaml file:
vi data-pod.yaml
  1. 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
  1. Use the following command to create the pod:
kubectl apply -f data-pod.yaml
  1. Use the following command to connect to the pod:
kubectl exec -it data-pod -n web -- sh
  1. 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
  1. Use the following command to list the contents of /tmp/data:
# ls /tmp/data/
Delete the pod and create a new pod and view volume data.
  1. Use the following command to delete the pod:

    kubectl delete po data-pod -n web
  2. Use the following command to modify the pod YAML:

    vi data-pod.yaml
  3. Change the following line in the data-pod.yaml file:

    name: data-pod2
  4. Use the following command to create a new pod:

    kubectl apply -f data-pod.yaml
  5. 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

Additional Resources

You have been given access to a two-node cluster. Within that cluster, a PersistentVolume has already been created. You must identify the size of the volume in order to make a PersistentVolumeClaim and mount the volume to your pod. Once you have created the PVC and mounted it to your running pod, you must copy the contents of /etc/passwd to the volume. Finally, you will delete the pod and create a new pod with the volume mounted in order to demonstrate the persistence of data. You must perform the following tasks in order to complete this hands-on lab:

  • All objects should be in the web namespace.
  • The PersistentVolumeClaim name should be data-pvc.
  • The PVC request should be 256 MiB.
  • The access mode for the PVC should be ReadWriteOnce.
  • The storage class name should be local-storage.
  • The pod name should be data-pod.
  • The pod image should be busybox and the tag should be 1.28.
  • The pod should request the PersistentVolumeClaim named data-pvc, and the volume name should be temp-data.
  • The pod should mount the volume named temp-data to the /tmp/data directory.
  • The name of the second pod should be data-pod2.

What are Hands-on Labs

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!