All cheatsheets
Kubernetes · Cheatsheet
kubectl + k9s Cheatsheet
Imperative & declarative kubectl, port-forwards, debugging tricks, and the k9s shortcuts that save your wrists.
Updated 2026-05-21 8 min
Context + namespaces
| kubectl config get-contexts | List configured clusters/contexts |
| kubectl config use-context prod-eks | Switch context |
| kubectl config set-context --current --namespace=app | Default namespace for current context |
| kubectx prod-eks / kubens app | Faster context/ns switching (krew plugins) |
| kubectl get ns | List all namespaces |
Inspect resources
| kubectl get all -n app | Everything in namespace |
| kubectl get pods -o wide | Pods + node + IP |
| kubectl get po -l app=api --watch | Watch pods by label |
| kubectl describe pod <name> | Events + container status |
| kubectl get events --sort-by=.lastTimestamp | Cluster events, freshest last |
| kubectl explain deployment.spec.strategy | Inline API docs |
| kubectl api-resources | grep ingress | Find resource short-names + group |
Logs & exec
| kubectl logs -f deploy/api | Follow deployment logs |
| kubectl logs -f pod -c sidecar --since=10m | Sidecar logs, last 10 min |
| kubectl logs --previous pod | Logs from crashed previous container |
| kubectl exec -it pod -- sh | Shell into a pod |
| kubectl debug node/ip-x -it --image=alpine | Privileged debug pod on a node (1.25+) |
| kubectl cp pod:/var/log/x.log ./x.log | Copy file out of pod |
Port-forward & proxy
| kubectl port-forward svc/api 8080:80 | Hit service on localhost:8080 |
| kubectl port-forward pod 5005:5005 | Forward a single pod port |
| kubectl proxy --port 8001 | API server proxy on localhost |
Imperative create / scale / rollout
| kubectl create deploy api --image=nginx | Quick deployment |
| kubectl scale deploy api --replicas=5 | Scale |
| kubectl set image deploy/api api=nginx:1.27 | Roll out a new image |
| kubectl rollout status deploy/api | Watch the rollout |
| kubectl rollout undo deploy/api | Undo last rollout |
| kubectl rollout history deploy/api | Past revisions |
Declarative apply
| kubectl apply -f manifests/ | Apply directory |
| kubectl apply -k overlays/prod/ | Apply Kustomize overlay |
| kubectl diff -f manifest.yaml | Server-side diff before apply |
| kubectl delete -f manifest.yaml | Delete what was created |
| kubectl get pod -o yaml > pod.yaml | Export YAML for editing |
Debugging cheats
| kubectl run tmp --rm -it --image=nicolaka/netshoot -- sh | Throwaway pod with curl/dig/nslookup/tcpdump |
| kubectl top pods / nodes | Live CPU + mem (needs metrics-server) |
| kubectl auth can-i delete pod -n app | Check RBAC for current user |
| kubectl get pod x -o jsonpath='{.status.containerStatuses[*].state}' | Drill into pod state |
k9s shortcuts (terminal UI)
| :pod / :deploy / :svc | Jump to resource view |
| /text | Filter by substring |
| d | Describe selected |
| l | Logs (Shift+L = previous) |
| s | Shell into pod |
| y | View YAML |
| e | Edit live |
| Ctrl+d | Delete (with confirm) |
| :xray pod | Resource dependency graph |
Want the full hands-on training behind this?
Cloudadhar batches walk you through every command in a real production setup — with labs, code reviews, and 1:1 doubt sessions.