kubectl Cheatsheet - Command Reference

All essential kubectl commands organized by Query, Describe, Scale, and Context. Step through groups when troubleshooting CrashLoop or connectivity issues.

Containers & Orchestration·19 commands·Last updated 2026-07-21
Back to Containers & Orchestration

Get Resources 5

kubectl get pods -n prod
List pods in a namespace
kubectl get pods -o wide
Show extra info: node and pod IP
kubectl get pods -A
List pods across all namespaces
kubectl get svc,ingress -n prod
Query Services and Ingresses at once
kubectl get events --sort-by=.lastTimestamp
Sort events by time, find scheduling/pull failures

Describe & Diagnose 5

kubectl describe pod <pod> -n prod
Check events, container status, probes for CrashLoop/Pending
kubectl logs <pod> -n prod
View pod logs
kubectl logs <pod> --previous
View logs from the previous crashed container, essential for CrashLoop
kubectl logs <pod> -c <container>
Logs for a specific container in a multi-container pod
kubectl exec -it <pod> -- sh
Shell into a pod container for debugging

Scale & Rollout 5

kubectl scale deploy/app --replicas=3
Adjust replica count
kubectl rollout status deploy/app
Check rolling update progress
kubectl rollout undo deploy/app
Rollback to previous version
kubectl set image deploy/app c=app:1.1
Update image to trigger rolling update
kubectl delete pod <pod>
Delete pod, controller recreates automatically

Context & Configuration 4

kubectl config get-contexts
List all cluster contexts
kubectl config use-context <ctx>
Switch current cluster context, essential for multi-cluster
kubectl config set-context --current --namespace=prod
Set default namespace, saves typing -n each time
kubectl top pod -n prod
View pod CPU/memory usage, requires metrics-server

💡 Tips

  • Troubleshooting order: get for status → describe for events → logs for app errors, add --previous for CrashLoop.
  • Run kubectl config get-contexts first to confirm the current cluster to avoid accidental operations on production.
  • kubectl top errors usually mean metrics-server is not installed, not a command syntax issue.