Skip to content

ludwigprager/CNCF-lab

Repository files navigation

CKA/CKAD hands-on exercises

Overview

Train for CKA and CKAD on a local kind kubernetes cluster.
Similar to 'killer.sh' or 'killercoda.com' but completely free and on your PC or laptop or VM.

Prerequisites

  • docker
  • envsubst
  • base64
  • ssh-keygen

Step-by-Step Guide

  1. Clone the repository
git clone https://github.com/ludwigprager/CKA-CKAD-exercises.git
  1. Start a randomly selected exercise
./CKA-CKAD-exercises/run-random-task.sh

Time Saving Settings

sudo yum -y install bash-completion
source <(kubectl completion bash | sed 's/kubectl/k/g' )
source /etc/bash_completion
alias k=kubectl

drc="dry-run=client"
drs="dry-run=server"

ns() {
  kubectl config set-context --current --namespace=$1
}

Multi-Container Pods (10%)

Pod Design (20%)

Exercise 01: requests and limits
Exercise 02: environment variables
Exercise 07: labels and annotations
Exercise 10: cron jobs

State Persistence (8%)

Exercise 05: hostPath
Exercise 06: hostPath in a persistent volume

Configuration (18%)

Exercise 03: rollout, rollback, record
Exercise 04: rollout

Observability (18%)

Exercise 09: readiness and liveliness

Services and Networking (13%)

Exercise 08: ClusterIP and network policy


Exercise Origins

  • CKA Practice Exam (mock questions) - Real 30 Practice questions and Answers

    • kw201 Q1 Deploy a pod called nginxpod with image nginx in controlplane, make sure pod is not scheduled in worker node.

    • kw202 Q2 Expose an existing pod called '$POD' as a service. Service should be '$SERVICE'.

    • kw203 Q3 Expose an existing pod called '$POD'. service name as '$SERVICE', service should access through Nodeport

    • kw204 Q4. you can find an existing deployment $DEPLOYMENT in $NAMESPACE namespace, scale down the replicas to $REPLICAS and change the image to $IMAGE

    • kw205 Q5, Auto scale the existing deployment '$DEPLOYMENT' in '$NAMESPACE' namespace at ${CPU}% of pod CPU usage, and set Minimum replicas=$MIN and Maximum replicas=$MAX.

    • kw206 Q6 Expose existing deployment in $NAMESPACE namespace namd as $DEPLOYMENT through Nodeport and Nodeport service should be $SERVICE

    • kw207 Q7 you can find a pod named $POD in the default namespace, please check the status of the pod and troubleshoot, you can recreate the pod if you want

    • kw208 Q8 Create a new PersistentVolume name web-pv. It should have a capacity of $CAPACITY, accesMode $ACCESSMODE, hostPath $HOSTPATH and no storageClassName defined.

    • kw208 Q8 Deploy a pod with the following specifcations:

    • kw209 Q9 Create a pod name my-busybox with the busybox:1.31.1 image. The pod should ru a sleep command for 4800 seconds. Verify that the pod is running in node worker1

    • kw210 Q10 the cluster run a three-tier web application: a frontend tier (port 80), an application tier (port 8080) and a backend tier (3306). The security team has mandated that the backend tier should only be accessible from the application tier.

    • kw211 Q11 Pods run in multiple namespaces. The security team has mandated that the $POD1 on $NAMESPACE1 namespace only accessible from the $POD2 in $NAMESPACE2.

    • kw212 Q12 you can find a pod named multi-pod is running in the cluster and that is logging to a volume. You need to insert a sidecar container into the pod that will also read the logs from the volume using this command $COMMAND.

    • kw213 Q13 Create a cronjob for running every 2 minutes with $IMAGE image. The jo name should be $JOB and it should print the current date and time to the console. After running the job save any one of the pod logs to below path $PATH.

  • CKA Certification SURE SHOT Questions | TOP 10 EXAM Questions | Must watch before exam - PART 1 kw1...

    • kw101 Q1 Given a cluster running version 1.26.0, upgrade the master node and worker node to version 1.27.0. e sure to drain the master and worker node efore upgrading it and uncordon it after the upgrade.
    • kw102 Q2 Create a snapshot of ETCD and save it to /root/backup/etcd-backup-new.db. Restore an old snapshot located at /root/backup/etcd-backup-old.db to /var/lib/etcd-backup
    • kw103 Q3 Join cka-$(whoami)-worker worker node to the cluster and you hav to deploy a pod in the cka-$(whoami)-worker, pod name should be $POD and image should be $IMAGE
    • kw105 Q5 Mark the worker node cka-$(whoami)-worker as unschedulable and reschedule all the pods running on it.
  • kodekloud CKA course kk...
    kk1xx: kodekloud/CKA/15 Mock Exams/243 Solution - CKA Mock Exam 1 (optional)-saq1a72kpg.bin

  • udemy 'Pass the CKA exam with these 100 practice questions'
    ex...

    • ex011 Q11: Create a new serviceaccount, clusterrole and clusterrolebinding. Make it possible to list the persisten volumes and create a pod with the new service account.

    • ex0301 Q0301: Take a backup of ETCD in file /tmp/snapshot.db

    • ex0302 Q0302: Restore ETCD using the backup file in /tmp/ex0302.snapshot.db into directory /var/lib/ex0302

    • ex052 Q52: Use JSONPATH to get a list of all the pods with name and namespace.

  • dgkanatsios d.configuration / secrets

    • secret1 Q1: Create a secret called mysecret with the values password=mypass
    • secret6 Q6: Create a Secret named 'ext-service-secret' in the namespace 'secret-ops'. Then, provide the key-value pair API_KEY=LmLHbYhsgWZwNifiqaRorH8T as literal.
    • secret7 Q7: Create a Pod named 'consumer' with the image 'nginx' in the namespace 'secret-ops' and consume the Secret as an environment variable. Then, open an interactive shell to the Pod, and print all environment variables.
    • secret8 Q8: Create a Secret named 'my-secret' of type 'kubernetes.io/ssh-auth' in the namespace 'secret-ops'. Define a single key named 'ssh-privatekey', and point it to the file 'id_rsa' in this directory.
    • secret9 Q9: Create a Pod named 'consumer' with the image 'nginx' in the namespace 'secret-ops', and consume the Secret as Volume. Mount the Secret as Volume to the path /var/app with read-only access. Open an interactive shell to the Pod, and render the contents of the file.
  • dgkanatsios d.configuration / configmaps

    • cm1 Q1: Create a configmap named config with values foo=lala,foo2=lolo
    • cm2 Q2: Create and display a configmap from a .env file
    • cm3 Q3: Create and display a configmap from a file, giving the key 'special'
    • cm4 Q4: Create a configMap called 'options' with the value var5=val5. Create a new nginx pod that loads the value from variable 'var5' in an env variable called 'option'
    • cm5 Q5: Create a configMap 'anotherone' with values 'var6=val6', 'var7=val7'. Load this configMap as env variables into a new nginx pod
    • cm6 Q6: Create a configMap 'cmvolume' with values 'var8=val8', 'var9=val9'. Load this as a volume inside an nginx pod on path '/etc/lala'. Create the pod and 'ls' into the '/etc/lala' directory.
  • killershell CKA

    • ks204 Q: Use namespace $NAMESPACE for the following task. Create a single pod $POD1 with image $IMAGE1. Configure a livenessprobe which simply runs 'true'. Also, configure a readinessprobe wich checks if the URL 'http://$SERVICE:$PORT' is reachable. Use command 'wget -T2 -O- http://$SERVICE:$PORT'.
    • ks212 Q: Use namespace $ NAMESPACE. Create a deployment $DEPLOYMENT with label $KEY=$VALUE and $REPLICAS replicas and image $IMAGE.
    • ks224 Q: start-exercise.sh:Q24 Create a NetworkPolicy called '$POLICY' in namespace '$NAMESPACE'. It should allow the ${TIER3}- pods only to
  • killershell CKS

    • ks318 Q: Namespace $NAMESPACE contains five secrets of type opaque which can be considered highly confidential. The latest incident-prevention-investigation revealed that service account $SERVICEACCOUNT had too broad access to the cluster for some time. This SA should have never had access to any secret in that namespace.

By Topic

Cluster Upgrade

Network Policies

  • kk35
  • kw210
  • kw211

More References

https://gist.github.com/bakavets/05681473ca617579156de033ba40ee7a

MISC

List all services in the default namespace using field selectors

show

kubectl get svc --field-selector metadata.namespace=default

List the services on your Linux operating system that are associated with Kubernetes

show

systemctl list-unit-files --type service --all | grep kube

List the status of the kubelet service running on the Kubernetes node

show

systemctl status kubelet

List all the services created in your Kubernetes cluster, across all namespaces

show

kubectl get svc -A

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published