kubectl Cheatsheet - Command Reference
All essential kubectl commands organized by Query, Describe, Scale, and Context. Step through groups when troubleshooting CrashLoop or connectivity issues.
Back to Containers & OrchestrationGet Resources 5
kubectl get pods -n prodList pods in a namespace
kubectl get pods -o wideShow extra info: node and pod IP
kubectl get pods -AList pods across all namespaces
kubectl get svc,ingress -n prodQuery Services and Ingresses at once
kubectl get events --sort-by=.lastTimestampSort events by time, find scheduling/pull failures
Describe & Diagnose 5
kubectl describe pod <pod> -n prodCheck events, container status, probes for CrashLoop/Pending
kubectl logs <pod> -n prodView pod logs
kubectl logs <pod> --previousView 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> -- shShell into a pod container for debugging
Scale & Rollout 5
kubectl scale deploy/app --replicas=3Adjust replica count
kubectl rollout status deploy/appCheck rolling update progress
kubectl rollout undo deploy/appRollback to previous version
kubectl set image deploy/app c=app:1.1Update image to trigger rolling update
kubectl delete pod <pod>Delete pod, controller recreates automatically
Context & Configuration 4
kubectl config get-contextsList all cluster contexts
kubectl config use-context <ctx>Switch current cluster context, essential for multi-cluster
kubectl config set-context --current --namespace=prodSet default namespace, saves typing -n each time
kubectl top pod -n prodView 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