CKAD · 5 November 2026 · 5 min read

kubectl aliases and settings that save minutes in the CKAD

A short alias, two shell variables, a namespace setting and three vim options remove most of the typing from the CKAD exam.

The kubectl shortcuts that save the most time in the CKAD and CKA are alias k=kubectl with tab completion, a $do variable for --dry-run=client -o yaml, a $now variable for instant deletes, a default namespace per context, and a vim setup for YAML. In a timed, hands-on exam the difference between passing and failing is often a few minutes, and those minutes are lost typing kubectl two hundred times, writing YAML by hand and fixing indentation.

TL;DR

  • alias k=kubectl, then complete -o default -F __start_kubectl k to keep tab completion.
  • export do="--dry-run=client -o yaml": k create deploy web --image=nginx $do > web.yaml.
  • export now="--force --grace-period 0": k delete pod x $now.
  • k config set-context --current --namespace=<ns> instead of -n on every command.
  • k explain for field names; set expandtab tabstop=2 shiftwidth=2 in vim for YAML.
  • Works the same in the CKA and the CKAD; set it up in under a minute at the start.

This article covers a small set of shell and editor settings that remove most of that friction. Set them up at the start of the exam, which takes under a minute, and use them in every practice session so they are second nature on the day.

A short alias for kubectl

The single most useful change is a one-letter alias:

Shell
alias k=kubectl

The exam environment may already have this alias set. Check with alias k before adding it, but adding it again does no harm.

An alias on its own loses tab completion, which is a real cost: completion saves typing resource names and catches spelling mistakes. Turn completion on for kubectl and attach it to the alias as well:

Shell
source <(kubectl completion bash)complete -o default -F __start_kubectl k

Now k get po followed by Tab completes Pod names, and k -n followed by Tab completes namespaces. If you use these settings on your own machine, put the lines in ~/.bashrc so they survive a new shell.

Two variables for common flags

Two groups of flags come up again and again. Store them in shell variables:

Shell
export do="--dry-run=client -o yaml"export now="--force --grace-period 0"

$do turns any create command into a YAML generator. Nothing is sent to the cluster; the manifest is printed instead. $now deletes a Pod without waiting for the normal graceful shutdown:

Shell
k delete pod broken-pod $now

Use $now with care. In the exam it saves waiting up to 30 seconds for a test Pod to shut down. On a production cluster a forced delete can leave a process running on the node after the API object has gone, so treat it as a practice and exam habit only.

Generate YAML instead of writing it

Writing a Deployment from memory means remembering where selector, template and matchLabels go, and getting the indentation right. Let kubectl do it:

Shell
k run web --image=nginx --port=80 $do > pod.yamlk create deploy web --image=nginx --replicas=3 $do > deploy.yamlk create job backup --image=busybox $do -- sh -c 'echo done' > job.yamlk create cronjob report --image=busybox --schedule="*/5 * * * *" $do -- date > cj.yamlk create configmap app-config --from-literal=MODE=prod $do > cm.yaml

Open the file, add what the generator could not (a probe, a volume, a security context), and apply it:

Shell
vim deploy.yamlk apply -f deploy.yaml

Keeping each task in its own file, named after the task number, also helps if you need to come back to it later.

You can also get a starting manifest from an object that already exists:

Shell
k get deploy web -o yaml > web-current.yaml

That output includes status and server-set fields such as uid and resourceVersion. Remove them before you reuse the file for a new object.

Set the namespace once

Many tasks say "in namespace payments". Typing -n payments on every command is easy to forget, and an object created in default by mistake will not be found by the grader. Set the namespace on the current context instead:

Shell
k config set-context --current --namespace=payments

Check where you are with:

Shell
k config view --minify | grep namespace

In today's exam each task is on its own host: you ssh to the host the task names and exit back to the base system afterwards. The task hosts already have k and completion, but anything you add yourself (the $do and $now variables, vim settings, the namespace) lives on that host only. Keep your setup to one line you can paste on each host: export do="--dry-run=client -o yaml" now="--force --grace-period 0", then set the namespace the task names. (See the Linux Foundation's important instructions for the CKA and CKAD.)

Look up fields with kubectl explain

When you know roughly what you need but not the exact field name, kubectl explain is faster than searching the documentation:

Shell
k explain pod.spec.containers.securityContextk explain deploy.spec.strategy.rollingUpdate

Add --recursive to see the whole tree of fields below a point, without the descriptions:

Shell
k explain pod.spec.volumes --recursive | less

This is the quickest way to answer questions like "is it readOnlyRootFilesystem or readOnlyFilesystem?" without leaving the terminal.

Make vim behave with YAML

YAML does not allow tab characters for indentation, and Kubernetes manifests normally use two spaces. If your editor inserts a tab, kubectl apply fails with a parse error that can take a while to spot. Add three settings to ~/.vimrc:

Shell
set expandtabset tabstop=2set shiftwidth=2

Or in one line:

Shell
echo 'set expandtab tabstop=2 shiftwidth=2' >> ~/.vimrc

expandtab turns the Tab key into spaces, tabstop sets how wide a tab looks, and shiftwidth sets how far >> and << indent a line. With these in place you can select a block in visual mode and press > to indent it by exactly one YAML level.

When you paste YAML copied from the documentation into vim, auto-indent can push each line further right. Run :set paste before pasting and :set nopaste afterwards to avoid it.

The full setup

Here is everything in one block, ready to type at the start of a session:

Shell
alias k=kubectlsource <(kubectl completion bash)complete -o default -F __start_kubectl kexport do="--dry-run=client -o yaml"export now="--force --grace-period 0"echo 'set expandtab tabstop=2 shiftwidth=2' >> ~/.vimrc

Keep it short. A long list of clever aliases you have to remember under pressure costs more time than it saves. These few cover the work you do on almost every task.

The kubectl quick reference on kubernetes.io is worth reading once, too, so you know where to find it if you need it.

Keep going

Shortcuts only save time once your fingers know them. Every lab in the Gazeek CKAD course runs on a real cluster, so you can set these up at the start of each lab and use them on real tasks with checks. For quick drills between labs, try the free practice questions in the Gazeek Memory Gym.

More from the blog