Why this level matters
The CKAD is 15 to 20 hands-on tasks in 2 hours, and you need 66% to pass. Each task tells you where to do the work: a host or cluster, and usually a namespace. If you build a perfect Deployment in the wrong cluster or namespace, the grader cannot find it, so the task scores nothing. This level covers three habits that guard against that:
- Switch contexts and namespaces on purpose.
- Set up a fast shell in under a minute.
- Check where you are before every task.
A reminder from Level 1: the purchase includes one retake and two simulator sessions, and the certification lasts two years. The quizzes in this course help you check your understanding, but they are no substitute for typing the commands yourself. Nothing here guarantees a pass. The curriculum is CNCF's (CC BY 4.0), and this course is independent of the Linux Foundation and CNCF, which do not endorse it.
Concept: what a context is
kubectl reads a kubeconfig file, which is ~/.kube/config by default. A context is a named set of three things:
- cluster: which API server to talk to
- user: which credentials to use
- namespace: the default namespace, optional (when it is empty, kubectl uses
default)
The file's current-context decides which context kubectl uses. A useful way to picture it: each context is a bookmark that holds a server, a login and a starting folder. The namespace belongs to the context. It is not a global setting.
Task 1: Create a second practice cluster
To practise switching, you need two clusters. In Level 1 you built ckad. Now add another.
- Create it:
kind create cluster --name ckad2 - List the contexts:
kubectl config get-contexts
kind names each contextCURRENT NAME CLUSTER AUTHINFO NAMESPACE kind-ckad kind-ckad kind-ckad * kind-ckad2 kind-ckad2 kind-ckad2kind-<cluster-name>. When kind creates a cluster it also makes it the current context, which is why the*is now onkind-ckad2.
Task 2: Switch context and set a namespace
- Switch to the first cluster:
kubectl config use-context kind-ckadSwitched to context "kind-ckad". - Create a namespace and make it the default for this context:
kubectl create namespace web kubectl config set-context --current --namespace=webContext "kind-ckad" modified. - Check the result. The NAMESPACE column for
kind-ckadshould now sayweb:kubectl config get-contexts - Switch to
kind-ckad2and runkubectl get pods. kubectl looks indefault, because that context still has no namespace set. The namespace stays with the context it was set on.
Two points to remember:
set-context --current --namespacedoes not check that the namespace exists. If you mistype it, kubectl just saysNo resources foundand gives no error.- For a single command you can override the namespace with
-n <namespace>instead.
Task 3: Set up a fast shell in under a minute
The official exam environment already has kubectl with the k alias and Bash completion. Your kind machine does not, so add them yourself and practise with the same setup you will have on exam day. Run these lines once:
echo 'source <(kubectl completion bash)' >> ~/.bashrc
echo 'alias k=kubectl' >> ~/.bashrc
echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
echo 'export do="--dry-run=client -o yaml"' >> ~/.bashrc
source ~/.bashrc
What each line does:
- Line 1 loads Tab completion for
kubectl. - Line 2 creates the
kalias. - Line 3 gives the alias the same completion. Without it,
k get po<Tab>does not complete, because Bash attaches completion to command names andkis a separate name. - Line 4 stores the dry-run flags in a variable.
k run web --image=nginx $doprints a manifest and creates nothing. Level 3 covers dry runs properly.
Test it: type k get no and press Tab. It should complete to k get nodes.
In the exam, $do and any aliases you add only last for the shell session or host you set them up on. If a task moves you to another host, re-run the export.
Task 4: The pre-task check
Do this before you touch any task:
- Run the switch command the task gives you. Copy and paste it so you avoid typos.
- Confirm the context:
k config current-context - Confirm the namespace:
If this prints nothing, you are ink config view --minify -o jsonpath='{..namespace}'; echodefault. - Choose how to target the namespace. Either set it on the context with
set-context --current --namespace, or add-n <namespace>to every command. Do not mix the two methods within one task. - Check your work afterwards with
k get <resource> -n <namespace>.
Timed practice (3 minutes)
Start with kind-ckad2 as the current context. Make kind-ckad the current context with web as its default namespace, then prove both without opening the kubeconfig file.
Solution:
k config use-context kind-ckad
k config set-context --current --namespace=web
k config current-context # kind-ckad
k config view --minify -o jsonpath='{..namespace}'; echo # web
What the exam asks about this
The exam does not test this skill as a separate task, but every task depends on it. Each task tells you which host or context and which namespace to use. Work in the wrong place and the task scores zero, however good the work is. Use the switch command the task gives you, check where you are, and use k and Tab completion to save seconds on every command.
Key takeaways
- A context is a cluster, a user and an optional namespace.
use-contextchanges which one kubectl uses. kubectl config set-context --current --namespace=<ns>sets the default namespace for the current context only.- The exam already has
kand completion. At home, set them up withcomplete -o default -F __start_kubectl kandexport do="--dry-run=client -o yaml". - Before every task: switch, check the context, check the namespace. After every task: check your work in the correct namespace.