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·24 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

FAQ 5

Q: How do I list pods across all namespaces?
A: kubectl get pods -A or kubectl get pods --all-namespaces lists pods in every namespace of the cluster.
Q: What is the difference between kubectl apply and kubectl create?
A: kubectl apply is declarative (recommended) and supports create and update; kubectl create is imperative and errors if the resource already exists.
Q: How do I view a pod log?
A: kubectl logs <pod> -n <namespace>; add -f to follow, or --previous to see the crashed container logs.
Q: How do I shell into a pod container?
A: kubectl exec -it <pod> -- sh (or /bin/bash); use -c <container> for multi-container pods.
Q: How do I check cluster node status?
A: kubectl get nodes lists all node statuses; kubectl describe node <name> shows detailed node info.

💡 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.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it