A fast kubectl reference
kubectl is the command-line client for the Kubernetes API server. This cheatsheet groups the commands you reach for daily — inspecting, applying, debugging and rolling out workloads — with the real flags and a one-line explanation. Filter by verb, search for a keyword, and copy the command straight to your clipboard.
How it works
Every kubectl command is a structured call to the cluster’s REST API. The first word after kubectl is the verb (get, describe, apply, delete, logs, exec, rollout, scale, config), followed by a resource type and name, then flags that shape the request and output.
Output flags are especially useful: -o wide adds columns, -o yaml dumps the full live object, and -o jsonpath='{...}' extracts a single field. Selectors with -l key=value operate on every matching object at once. The cheatsheet’s group filter maps directly to these verbs so you can scan one category at a time.
Most-reached-for commands
Inspecting workloads
kubectl get pods -n NAMESPACE # List pods in a namespace
kubectl get pods -A # All pods across all namespaces
kubectl describe pod POD -n NAMESPACE # Full pod detail including events
kubectl get events --sort-by=.lastTimestamp -n NAMESPACE # Chronological events
Logs and debugging
kubectl logs POD # Current container logs
kubectl logs POD -f # Follow (stream) logs
kubectl logs POD --previous # Logs from the prior crashed container
kubectl exec -it POD -- sh # Interactive shell inside a pod
kubectl exec -it POD -c CONTAINER -- sh # Shell into a specific container
Applying and deleting
kubectl apply -f manifest.yaml # Create or update from a file
kubectl diff -f manifest.yaml # Preview what would change
kubectl apply -f manifest.yaml --dry-run=server # Validate without applying
kubectl delete -f manifest.yaml # Delete resources from a file
Rollouts and scaling
kubectl rollout status deploy/NAME # Watch a rollout complete
kubectl rollout history deploy/NAME # See revision history
kubectl rollout undo deploy/NAME # Revert to previous revision
kubectl scale deploy/NAME --replicas=3 # Set replica count directly
Context and namespace
kubectl config get-contexts # List all contexts
kubectl config use-context CONTEXT # Switch cluster/context
kubectl config set-context --current --namespace=NS # Set default namespace
Tips and examples
- Watch resources change in real time with
-w, for examplekubectl get pods -wwhile a rollout proceeds. - Debug failures by combining describe and events:
kubectl describe pod my-pod
kubectl get events --sort-by=.lastTimestamp
- Set short aliases for speed: many engineers alias
ktokubectland usekgpforkubectl get pods. - Always validate before applying to production with
kubectl diff -f manifest.yamlandkubectl apply -f manifest.yaml --dry-run=server. - Placeholders like
POD,NAME,NSanddeploy/NAMEin the copied commands should be replaced with your real resource names.