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