Pass CKAD smart not hard
By: Ronak Patel
Tags: Cloud Services, Kubernetes, Cloud Native, Technology, Cloud

After playing with Kubernetes for almost a year and a half, it motivated me to challenge myself and pursue the certification.

I have recently passed my CKAD (Certified Kubernetes Application Developer) Certification on the first attempt with 89 percentiles and would like to share my experience with other prospective developers/DevOps enthusiasts looking to pursue the path.

By now you may know that CKAD (and CKA) is an open book exam and you can use Kubernetes Documentation for referring the commands and yaml snippets. It challenges your practical knowledge of defining application resources and uses core primitives to build, monitor, and troubleshoot scalable applications and tools in Kubernetes. rather than testing for book written fundamentals. The exam is 120 minutes (2 hours) long and tests various features such as Pod design, configurations, and environment variable management, logs and observability, networking and services, and storage persistence. As it will be a race against time, awareness, and utilization of the resources is crucial. Here we will see a few of them as I used in my test.

Setup an alias

Setting up an alias is a gift when the clock is ticking faster than you expect hence as soon as you get your terminal up and running, set up the alias as below

alias k=kubectl

Tip: You may have to work on different servers/contexts hence you you will have to set the alias for all servers individually.

As often, you will play with the dry-run option to generate resource scaffolding, setting up an alias with that option would be a time saver too.

alias kdr="kubectl --dry-run=client -o yaml"

Use Short names

Believe me, you would thank yourself for mastering the short names of resources. Below is the list of short names as of version 1.19:

Kubectl API Resources with short names

kubectl api-resources will provide the up-to-date api resources details along with short names.

Imperative Commands

Keeping imperative commands handy is essential for not only CKAD/CKA certification exam but also to spin up Kubernetes resources quickly. Here are imperative commands for some widely used resources using kubectl (version ≥ 1.18):

Before you start, please note that kubectl version 1.19 onwards “kubectl run” command will only generate pod. To create all other resources, use “kubectl create” command.

Create a namespace

kubectl create ns dev-ns

Create a pod label

kubectl run busybox --image=busybox -l tier=webapp

Create a pod with advanced settings

kubectl run busybox --image=busybox --limits "cpu=200m,memory=512Mi" --requests "cpu=100m,memory=256Mi" --command -- sh -c "sleep 3600" -o yaml --dry-run=client

Update pod/container configuration/property

kubectl get pod busybox -o yaml > busybox.yaml

You can update/correct a container image, activeDeadlineSeconds or pod tolerations in running pod inline with kubectl edit pod command.

kubectl edit pod busybox

Create a deployment

kubectl create deployment redis-deployment --image=redis --replicas=2

Scale deployment to 5 replicas

kubectl scale deployment/redis-deployment --replicas=5

Update container image in the deployment

kubectl set image deployment.v1.app/redis-deployment redis=redis:alpine

Update container resources in the deployment

kubectl set resources deployment.v1.apps/redis-deployment -c=redis --limits=cpu=200m,memory=512Mi

You can easily edit any field/property of the POD template with edit deployment command as well. Since the pod template is a child of the deployment specification, with every change the deployment will automatically delete and create a new pod with the fresh changes.

kubectl edit deployment redis-deployment

Create a cronjob

kubectl create cronjob my-job --schedule="*/1 * * * *" --image=busy-box

Create a configMap

kubectl create configmap my-config-map --from-literal=APP_COLOR=green

Create a secret

kubectl create secret generic app-secret --from-literal=USERNAME=root --from-literal=PASSWORD=Test

This post alone does not pass the certification, but it will definitely help you complete tasks promptly. There are many resources, videos and posts are available on the internet including the official Kubernetes documentation, but the intention here is to share tips and tricks I used.

Happy kubectl-ing!!!