kubectl Speed for Hands On Exams

Topics Covered

Setting Up Your Terminal

The k alias and completion

Short resource names

Shortcut variables

vim settings for YAML

vim motions worth knowing

tmux basics

Keep the setup short

Measure your own speed

Small habits that add up

Every minute you save on typing is a minute you can spend on a hard task. On a two hour exam with fifteen to twenty tasks, the difference between a candidate who types kubectl in full with no completion and one who uses a short alias with completion, shortcut variables and a tuned editor adds up to ten or fifteen minutes. That is often the margin between passing and failing. This section covers the small amount of setup worth doing at the start, and the habits that make it pay off.

The k alias and completion

The exam environment usually provides an alias k for kubectl and bash completion for both. Do not assume it; check in the first few seconds:

bash
alias k
type _complete_alias 2>/dev/null; complete -p k

If the alias is missing, add it, and wire completion to it. kubectl ships its own completion script, and the last line below tells bash to use kubectl's completion function for the alias as well:

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

Completion is the single biggest speed gain available. Typing k get po and pressing tab completes resource names, pod names, namespaces after -n, and even flag names. It also prevents typos in object names, which the grader checks literally. Practise using tab for every name rather than typing it, until reaching for tab is automatic.

If you want these lines to survive new terminal tabs during the exam, append them to the shell startup file:

bash
1cat >> ~/.bashrc <<'EOF'
2alias k=kubectl
3source <(kubectl completion bash)
4complete -o default -F __start_kubectl k
5EOF
6source ~/.bashrc

Short resource names

kubectl accepts short names for most resources, which saves keystrokes on every command. You should know the common ones without thinking: po for pods, deploy for deployments, rs for replicasets, svc for services, ns for namespaces, cm for configmaps, sa for serviceaccounts, pv and pvc for persistent volumes and claims, netpol for networkpolicies, ing for ingresses, sts for statefulsets, ds for daemonsets, cj for cronjobs, sc for storageclasses, hpa for horizontalpodautoscalers and ep for endpoints, an API deprecated since v1.33 in favour of EndpointSlices. When you forget one, ask the cluster:

bash
kubectl api-resources | grep -i network

The SHORTNAMES column lists every alias, and the NAMESPACED column tells you whether the resource lives in a namespace, which matters when a task asks you to find all instances of something.

Shortcut variables

Two variables cover most of the remaining repetitive typing. The first produces YAML from any create or run command without sending it to the cluster. The second deletes a pod immediately instead of waiting for its grace period:

bash
1export do="--dry-run=client -o yaml"
2export now="--force --grace-period=0"
3
4k run web --image=nginx:1.27 $do > web.yaml
5k delete pod web $now

The first variable is used dozens of times in a session; the next section is entirely about it. The second is useful because a normal pod deletion waits up to thirty seconds for the container to shut down cleanly. In practice tasks you are deleting pods you are about to recreate, so the wait is wasted. Use it only on pods: on other objects, forced deletion offers little benefit and can leave things in odd states.

A short opening routine sets up the alias, completion, a dry run shortcut and vim for YAML.

vim settings for YAML

Most YAML errors in the exam are indentation errors, and most of those come from tabs or from the editor auto indenting pasted text. Three settings prevent nearly all of them. Put them in the vim startup file at the start of the exam:

bash
1cat >> ~/.vimrc <<'EOF'
2set expandtab
3set tabstop=2
4set shiftwidth=2
5EOF

expandtab turns the tab key into spaces, which YAML requires. tabstop and shiftwidth make each indent level two spaces, the convention in Kubernetes manifests. Some candidates add set number to show line numbers, which helps when an error message names a line, and set autoindent, which keeps the current indent when you press enter. If pasting from the docs pushes lines out of alignment, type :set paste before pasting and :set nopaste after.

vim motions worth knowing

You do not need to be a vim expert, but a dozen commands make editing manifests far faster than arrow keys:

  • i to insert before the cursor, a to append after it, o to open a new line below, Esc to return to normal mode.
  • dd to delete a line, yy to copy a line, p to paste it below, u to undo, ctrl r to redo.
  • A number before a command repeats it: 5dd deletes five lines.
  • gg jumps to the top, G to the bottom, a number then G jumps to that line.
  • /text searches forward, n jumps to the next match.
  • Shift v starts selecting whole lines; the greater than and less than keys then indent or outdent the selection by one level.
  • :wq saves and quits, :q! quits without saving.

The visual line indent is the one people forget and need most. When you paste a block that should be nested one level deeper, select it with shift v and press the greater than key once instead of fixing each line.

If you prefer nano, it is available too. The important thing is that you are fluent in whichever editor you choose. Learning vim in the final week is a poor trade; pick the editor you already know and set it up for two space indents.

tmux basics

Some candidates like to split the terminal so they can watch a resource in one pane while working in another, for example running kubectl get pods -w while rolling out a change. If tmux is available in your environment, the essentials are short. Start it with tmux, then press ctrl b followed by one key:

bash
1tmux
2# ctrl b then %      split side by side
3# ctrl b then "      split top and bottom
4# ctrl b then arrow  move between panes
5# ctrl b then z      zoom the current pane, again to unzoom
6# ctrl b then c      new window, ctrl b then n for the next one

tmux is optional. The remote desktop terminal emulator usually supports multiple tabs, which is often simpler. Only use tmux in the exam if you already use it daily; a confusing pane layout costs more than it saves.

Keep the setup short

The whole routine should fit in under a minute. The order that works for most people is: check the alias and completion, export the dry run variable, write the three vim lines. Anything else is optional. Rehearse the routine at the start of every practice session, so on exam day you type it without thinking and start the first task calm and ready.

Measure your own speed

It is hard to feel the gains from a faster setup, so measure them. Pick five small tasks: create a pod with a label, create a Deployment with three replicas, expose it, create a ConfigMap from two literals, and write all pod names in a namespace to a file. Time yourself doing all five with full kubectl commands and no completion, then again with the alias, completion and the dry run variable. Most people see the second run take half the time or less, and make fewer typos. Repeat the test once a week during your preparation. The times keep dropping long after the setup itself stops changing, because the real gain is fluency: knowing which command to reach for without thinking.

Small habits that add up

A few more habits are worth building during practice. Use the up arrow and ctrl r to recall and edit earlier commands rather than retyping them; ctrl r searches your history as you type, so typing expose finds your last expose command. Use ctrl a and ctrl e to jump to the start and end of a line, and ctrl w to delete the previous word, which is faster than holding backspace. When you need the same namespace flag on a run of commands, type the first command fully and then edit only the end of each recalled line. None of these is specific to Kubernetes, but each one shaves seconds off a task, and over fifteen or twenty tasks the seconds become minutes.

Finally, keep a scratch file of the commands you use most often and their exact flags while you study. Rewriting that list from memory once a week is a quick test of how well the commands have stuck, and the gaps it reveals tell you what to drill next.

Tab for every name

Use completion for object names, namespaces and flags instead of typing them. It is faster, and it removes the typos that make the grader's name checks fail even when everything else is right.