Shell Shortcuts, Image Loading, and Tooling
SummaryComplete shell configuration with kubectl aliases, bash completion,...
Complete shell configuration with kubectl aliases, bash completion,...
Complete shell configuration with kubectl aliases, bash completion, dry-run shortcuts, VS Code extensions, and krew plugins. Includes the full .bashrc additions and three hands-on exercises.
Shell Shortcuts, Image Loading, and Tooling
The CKAD exam is a race against time. You have 120 minutes for 15–20 tasks. Every keystroke matters. The difference between typing kubectl get pods --namespace kube-system and k get po -n kube-system is three seconds. Multiply that across hundreds of commands during the exam, and you are looking at minutes saved — enough for one more task completed.
This section builds a shell configuration that turns kubectl into an instrument you can operate at speed. Everything here is allowed in the exam environment (the exam provides kubectl autocompletion and permits aliases).
Essential Aliases
Add these aliases to your ~/.bashrc (or ~/.bash_profile on macOS):
# Core alias — you will type 'k' thousands of times
alias k=kubectl
# Apply manifests
alias kaf='kubectl apply -f'
# Dry-run shortcut — generate YAML without creating resources
export do='--dry-run=client -o yaml'
# Force delete — skip graceful shutdown (useful for stuck Pods in lab)
export now='--force --grace-period 0'
How the Shortcuts Work in Practice
The do and now variables are used inline with kubectl commands:
# Generate a Pod manifest without creating it
k run nginx --image=nginx $do > pod.yaml
# Generate a Deployment manifest
k create deployment web --image=nginx --replicas=3 $do > deploy.yaml
# Generate a Service manifest
k expose deployment web --port=80 --target-port=80 $do > svc.yaml
# Force delete a Pod immediately (lab only — never in production)
k delete pod stuck-pod $now
The $do pattern is particularly powerful. Instead of memorizing the --dry-run=client -o yaml flags, you type two characters. The exam allows you to define variables and aliases in your terminal session — take the first 60 seconds of the exam to set these up.
Additional Useful Aliases
# Shortcut for common resource types
alias kgp='kubectl get pods'
alias kgd='kubectl get deployments'
alias kgs='kubectl get services'
alias kgn='kubectl get nodes'
alias kgi='kubectl get ingress'
# Describe resources
alias kdp='kubectl describe pod'
alias kdd='kubectl describe deployment'
# Logs
alias kl='kubectl logs'
alias klf='kubectl logs -f'
# Delete
alias kdel='kubectl delete'
# Watch resources
alias kw='kubectl get pods -w'
# Get all resources in current namespace
alias kga='kubectl get all'
# Switch namespace quickly
alias kns='kubectl config set-context --current --namespace'
The kns alias is a time-saver. Instead of appending -n <namespace> to every command, switch your active namespace:
kns my-namespace
k get pods # now shows pods in my-namespace
Exam tip: At the start of each exam task, check which namespace you should be working in. Many candidates lose points by creating resources in the wrong namespace. Use
knsimmediately after reading each task.
Bash Completion
Kubectl ships with built-in bash completion. Without it, you cannot tab-complete resource names, flags, or resource types. Enable it:
# Enable kubectl completion
source <(kubectl completion bash)
# Make completion work with the 'k' alias
complete -F __start_kubectl k
After sourcing these lines, typing k get po<TAB> expands to k get pods, and k describe pod nginx-<TAB> completes the full Pod name from the cluster.
Test it immediately after adding to your .bashrc:
source ~/.bashrc
k get <TAB><TAB>
You should see a list of all Kubernetes resource types. If completion does not work, ensure bash-completion is installed:
# Ubuntu/Debian
sudo apt-get install -y bash-completion
# macOS
brew install bash-completion@2
The Complete .bashrc Additions
Here is the full block to add at the end of your ~/.bashrc. Copy it exactly:
# ============================================
# CKAD Kubernetes Shell Configuration
# ============================================
# Core aliases
alias k=kubectl
alias kaf='kubectl apply -f'
export do='--dry-run=client -o yaml'
export now='--force --grace-period 0'
# Resource shortcuts
alias kgp='kubectl get pods'
alias kgd='kubectl get deployments'
alias kgs='kubectl get services'
alias kgn='kubectl get nodes'
alias kgi='kubectl get ingress'
alias kdp='kubectl describe pod'
alias kdd='kubectl describe deployment'
alias kl='kubectl logs'
alias klf='kubectl logs -f'
alias kdel='kubectl delete'
alias kw='kubectl get pods -w'
alias kga='kubectl get all'
alias kns='kubectl config set-context --current --namespace'
# Bash completion
source <(kubectl completion bash)
complete -F __start_kubectl k
# Editor for kubectl edit
export KUBE_EDITOR="vim"
# kubectl output formatting
export COLUMNS=200
The KUBE_EDITOR variable controls which editor opens when you run k edit. The exam environment typically provides vim and nano. The COLUMNS variable widens the output of kubectl get commands so that long names and fields are not truncated.
Apply the configuration:
source ~/.bashrc
VS Code Extensions
While you cannot use VS Code during the exam, it dramatically speeds up learning and practicing. Install these extensions for your study sessions:
Kubernetes (ms-kubernetes-tools.vscode-kubernetes-tools)
Provides a sidebar that shows your cluster resources in a tree view. You can view, edit, and delete resources directly. It also adds YAML validation for Kubernetes manifests — it will underline invalid fields and suggest corrections.
code --install-extension ms-kubernetes-tools.vscode-kubernetes-tools
YAML (redhat.vscode-yaml)
Adds YAML language support with schema validation. Combined with the Kubernetes extension, it provides autocomplete for Kubernetes manifest fields — type apiV and it suggests apiVersion: v1.
code --install-extension redhat.vscode-yaml
Configuration
Add this to your VS Code settings.json to enable Kubernetes schema validation for YAML files:
{
"yaml.schemas": {
"kubernetes": "*.yaml"
},
"editor.tabSize": 2,
"files.associations": {
"*.yaml": "yaml"
}
}
Practice note: During study, use VS Code to write manifests so you learn the field names with autocomplete. During practice exams, switch to
vimin the terminal to simulate exam conditions. The goal is to internalize the manifest structures so deeply that you do not need autocomplete.
kubectl Plugins with Krew
Krew is a plugin manager for kubectl. It provides access to hundreds of community-built plugins. Two are particularly useful for CKAD preparation.
Installing Krew
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
)
# Add krew to PATH
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
Add the export PATH line to your ~/.bashrc to make it permanent.
kubectx and kubens
kubectx switches between cluster contexts. kubens switches between namespaces. Both are faster than the native kubectl config commands.
kubectl krew install ctx
kubectl krew install ns
Usage:
# List all contexts
kubectl ctx
# Switch to the ckad-lab context
kubectl ctx kind-ckad-lab
# List all namespaces
kubectl ns
# Switch to the kube-system namespace
kubectl ns kube-system
# Switch back to default
kubectl ns default
These commands are interactive — they accept partial names and will prompt if ambiguous. They save time when you are working across multiple namespaces, which happens frequently on the exam.
Exam note: Krew and its plugins may not be available in the exam environment. The exam does provide
kubectl config use-contextand you can set namespace withkubectl config set-context --current --namespace=<ns>. Practice both methods — use krew plugins in daily study, but know the native commands for the exam.
Other Useful Krew Plugins
# View resource utilization
kubectl krew install resource-capacity
# Decode secrets inline
kubectl krew install view-secret
# Neat — clean up kubectl output YAML
kubectl krew install neat
The neat plugin is worth highlighting. When you run k get pod nginx -o yaml, the output includes managed fields, status, and metadata clutter. kubectl neat strips all of that:
k get pod nginx -o yaml | kubectl neat
The result is a clean manifest you can save and reapply — useful for understanding what a resource looks like without the noise.
Working with Images in Kind
Combining what you learned about image loading with your new aliases creates an efficient workflow:
# Build the image
docker build -t my-app:v1 .
# Load it into Kind
kind load docker-image my-app:v1 --name ckad-lab
# Create a Pod using the image
k run my-app --image=my-app:v1 --image-pull-policy=IfNotPresent
# Verify the Pod is running
kgp
For rapid iteration during development:
# Rebuild, reload, and restart
docker build -t my-app:v2 . && \
kind load docker-image my-app:v2 --name ckad-lab && \
k set image pod/my-app my-app=my-app:v2
Verifying Your Setup
Run this checklist to confirm everything works:
# 1. Kind cluster is running
kubectl get nodes
# Expected: 3 nodes, all Ready
# 2. Aliases work
k get nodes
# Expected: same output as above
# 3. Bash completion works
k get <TAB><TAB>
# Expected: list of resource types
# 4. Dry-run variable works
k run test --image=nginx $do
# Expected: YAML output, no resource created
# 5. Namespace switching works
kns kube-system
k get pods
kns default
# Expected: system pods visible, then back to default
If all five checks pass, your development environment is ready.
Exercises
Exercise 1: Spin Up a 3-Node Kind Cluster
Create a Kind cluster named ckad-practice with 1 control-plane node and 2 worker nodes. The control-plane node should have port mappings for ports 80 and 443, and a node label ingress-ready=true. Verify that all three nodes are in Ready status.
Requirements:
- Write a
kind-cluster.yamlconfiguration file - Create the cluster with name
ckad-practice - Confirm all nodes show
Readystatus - Confirm the control-plane node has the
ingress-ready=truelabel
Exercise 2: Configure All Aliases and Verify Bash Completion
Add all shell aliases and bash completion configuration from this section to your ~/.bashrc. Source the file and verify:
- The
kalias works forkubectl - Tab completion works with the
kalias - The
$dovariable generates YAML without creating resources - The
knsalias switches your active namespace
Requirements:
- All aliases from the complete
.bashrcblock are present source ~/.bashrcsucceeds without errorsk get nodesreturns the same output askubectl get nodesk run verify --image=nginx $dooutputs valid YAMLkns kube-system && k get podsshows system pods
Exercise 3: Load a Custom Docker Image into Kind and Run It as a Pod
Create a minimal Dockerfile that runs a web server, build the image, load it into your Kind cluster, and run it as a Pod.
Requirements:
- Write a
Dockerfilewith a web server (usenginx:alpineorpython:3-alpinewith a simple HTTP server) - Build the image with a tag (not
latest) - Load the image into the Kind cluster using
kind load docker-image - Create a Pod using the loaded image with
imagePullPolicy: IfNotPresent - Verify the Pod reaches
Runningstatus - Use
kubectl port-forwardto verify the web server responds