Stage 7 · Master
Exam Strategy & Study Plans
kubectl Speed & Aliases
Imperative commands, --dry-run, aliases, and vim setup — faster kubectl for the exam.
Essential Aliases
Aliases save time by replacing long commands with short ones. On the CKA/CKAD exam, every second counts. Set up aliases before the exam starts.
# Add to ~/.bashrc or ~/.zshrc
alias k='kubectl'
alias kgp='kubectl get pods'
alias kgs='kubectl get svc'
alias kgn='kubectl get nodes'
alias kgd='kubectl get deployments'
alias kdp='kubectl describe pod'
alias kds='kubectl describe svc'
alias kdn='kubectl describe node'
alias kl='kubectl logs'
alias kex='kubectl exec -it'
alias ka='kubectl apply -f'
alias kd='kubectl delete -f'
alias kaf='kubectl apply -f'
alias kdf='kubectl delete -f'
alias kcu='kubectl config use-context'
alias kcg='kubectl config get-contexts'These aliases reduce typing significantly. 'k' for kubectl, 'kgp' for get pods, 'kdp' for describe pod. Practice with these aliases before the exam so they become second nature.
The exam environment lets you set up aliases before starting. Spend the first 2 minutes setting up your aliases and shortcuts. This investment pays for itself many times over during the 2-hour exam.
The --dry-run Pattern
The --dry-run=client -o yaml pattern generates YAML without applying it. This is the fastest way to create valid manifests during the exam.
# Generate a Pod manifest
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
# Generate a Deployment manifest
kubectl create deployment web --image=nginx --replicas=3 --dry-run=client -o yaml > deploy.yaml
# Generate a Service manifest
kubectl expose deployment web --port=80 --type=NodePort --dry-run=client -o yaml > svc.yaml
# Generate and apply directly
kubectl run nginx --image=nginx --dry-run=client -o yaml | kubectl apply -f -The --dry-run=client flag generates the manifest locally without contacting the API server. The -o yaml flag outputs it in YAML format. Pipe through kubectl apply -f - to apply directly.
Imperative Command Reference
# Pods
kubectl run nginx --image=nginx:1.25 --port=80
# Deployments
kubectl create deployment web --image=nginx --replicas=3
# Services
kubectl expose deployment web --port=80 --type=NodePort
# ConfigMaps
kubectl create configmap my-config --from-literal=key1=value1
# Secrets
kubectl create secret generic my-secret --from-literal=key=value
# Namespaces
kubectl create namespace my-ns
# Jobs
kubectl create job my-job --image=busybox -- echo hello
# CronJobs
kubectl create cronjob my-cron --image=busybox --schedule="*/5 * * * *" -- echo hello
# RBAC
kubectl create role pod-reader --verb=get,list,watch --resource=pods
kubectl create rolebinding my-binding --role=pod-reader --user=developerThese imperative commands create valid resources without writing YAML. They are 2-3x faster than writing manifests manually. Use them whenever possible during the exam.
Vim Configuration
Vim is the default editor in the exam environment. Configure it for YAML editing before the exam starts.
# Set up vim for YAML editing
cat > ~/.vimrc <<EOF
set tabstop=2
set shiftwidth=2
set expandtab
set autoindent
syntax on
EOF
# Or use during the exam
# :set tabstop=2 shiftwidth=2 expandtab
# :syntax onYAML uses 2-space indentation. Configure vim to use spaces instead of tabs. This prevents indentation errors in your manifests.
Shell Shortcuts
# Use tab completion
kubectl get po<TAB> # Completes to pods
kubectl get pods -o j<TAB> # Completes to json
# Use history
!! # Repeat last command
!k # Last command starting with k
history | grep kubectl # Find previous kubectl commands
# Use variables
export NS=production
kubectl get pods -n $NS
# Pipe and filter
kubectl get pods -o yaml | grep -A 5 "image:"
kubectl get pods --all-namespaces | grep -v RunningTab completion, history, and variables save significant time. Practice using them until they are natural.
Auto-Completion
# For bash
source <(kubectl completion bash)
alias k=kubectl
complete -o default -F __start_kubectl k
# For zsh
source <(kubectl completion zsh)
alias k=kubectlAuto-completion lets you press Tab to complete resource names, flags, and namespaces. This is invaluable during the exam when you need to work quickly.
Do not set up aliases and shortcuts for the first time during the exam. Practice with them for at least a week before the exam so they are second nature. Muscle memory is critical for speed.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.