CKA Practice Exam: Part 2

Hands-On Lab

 

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

CKA Practice Exam: Part 2

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.

Log in to the Kube Master server using the credentials on the lab page (either in your local terminal, using the Instant Terminal feature, or using the public IP), and work through the objectives listed.

Create the PersistentVolumeClaim.

  1. Check if there is already a web namespace:

    kubectl get ns
  2. Now, we're going to create a PersistentVolumeClaim. Rather than write the YAML from scratch, search the documentation for "kubectl apply persistentvolumeclaim". Then, find the most appropriate YAML, add it to the following, and run the command:

    vi data-pvc.yaml #copy and paste from docs
  3. Change the following in the data-pvc.yaml file:

    name: data-pvc
    namespace: web
    storageClassName: local-storage
    storage: 256Mi
  4. Create the PVC:

    kubectl apply -f data-pvc.yaml

Create a pod mounting the volume and write data to the volume.

  1. Create the YAML for a busybox pod:

    kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'sleep 3600' > data-pod.yaml
  2. Edit the data-pod.yaml file:

    vi data-pod.yaml
  3. Add the following to the data-pod.yaml file:

      namespace: web
     volumeMounts:
        - name: temp-data
          mountPath: /tmp/data
      volumes:
      - name: temp-data
        persistentVolumeClaim:
          claimName: data-pvc
  4. Create the pod:

    kubectl apply -f data-pod.yaml
  5. Connect to the pod:

    kubectl exec -it data-pod -n web -- sh
  6. Copy the contents of the etc/passwd file to /tmp/data:

    # cp /etc/passwd /tmp/data/passwd
  7. List the contents of /tmp/data:

    # ls /tmp/data/
  8. Exit out of the shell:

    # exit

Delete the pod and create a new pod and view volume data.

  1. Delete the pod:

    kubectl delete po data-pod -n web
  2. Modify the pod YAML:

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

    name: data-pod2
  4. Create a new pod:

    kubectl apply -f data-pod.yaml
  5. Connect to the pod:

    kubectl exec -it data-pod2 -n web -- sh
  6. View the contents of the volume:

    # ls /tmp/data

Conclusion

Congratulations on completing this portion of the practice exam!