Kubernetes Commands Cheat Sheet
A kubectl and Kubernetes commands cheat sheet for contexts, workloads, logs, debugging, scaling, rollout and safe resource changes.

This Kubernetes cheat sheet covers common kubectl tasks. Always confirm the active context and namespace before changing a cluster.
Context and discovery
kubectl config current-context | Show the active cluster context. |
kubectl config get-contexts | List available contexts. |
kubectl get namespaces | List namespaces. |
kubectl api-resources | List resource types supported by the server. |
kubectl version | Show client and server version information. |
Inspect workloads
kubectl get pods -n NAME | List pods in a namespace. |
kubectl get deploy,svc -n NAME | List deployments and services. |
kubectl describe pod POD -n NAME | Show status, events and configuration. |
kubectl logs POD -n NAME | Read container logs. |
kubectl logs POD --previous -n NAME | Read logs from the previous crashed container. |
Apply, scale and roll out
kubectl diff -f FILE | Preview declarative changes. |
kubectl apply -f FILE | Apply configuration. |
kubectl scale deploy/APP --replicas=3 -n NAME | Change replica count. |
kubectl rollout status deploy/APP -n NAME | Watch rollout progress. |
kubectl rollout undo deploy/APP -n NAME | Roll back to the previous revision. |
Debug safely
Start with events, status and logs. Use kubectl exec only when the image contains the required tool, and prefer an approved debug-container workflow for minimal images. Avoid broad delete commands and never assume the default namespace or current context is correct.
Worked example: inspect one namespace
development-cluster, demo and web are placeholders. Substitute an authorized existing context, namespace and deployment.
kubectl config get-contexts
kubectl --context=development-cluster -n demo get deployment web
kubectl --context=development-cluster -n demo get pods -o wide
kubectl --context=development-cluster -n demo describe deployment webExplicit context and namespace show the target on each command. Compare desired and actual readiness and look for restarts. Running does not necessarily mean ready to serve requests.
Choose the affected pod and container from the output, then inspect logs:
kubectl --context=development-cluster -n demo logs POD -c CONTAINER --tail=100
kubectl --context=development-cluster -n demo logs POD -c CONTAINER --previous --tail=100The previous-log request can fail if no earlier container instance exists. That describes available logs, not application health. The pod debugging guide covers deeper inspection.
Preview a change and verify its outcome
Review the manifest, including its namespaces, and confirm authorization for every resource. A command-line namespace does not make an arbitrary manifest safe.
kubectl --context=development-cluster -n demo diff -f deployment.yaml
kubectl --context=development-cluster -n demo apply -f deployment.yaml
kubectl --context=development-cluster -n demo rollout status deployment/web --timeout=120skubectl diff returns 0 for no differences, 1 for differences and more than 1 for an error. Inspect its output instead of treating every nonzero result as a failed preview. See the diff reference.
A successful rollout is not an end-to-end test. Check readiness, routing and a representative request. Inspect history and the desired revision before rolling back. A deployment rollback does not restore database contents, all configuration or external services.
These examples were checked against documentation, not run against a cluster. Consult the kubectl reference for further context and resource commands.
Frequently asked questions
What is kubectl?
kubectl is the command-line tool that communicates with a Kubernetes cluster control plane through the Kubernetes API.
How do I check my current Kubernetes cluster?
Run kubectl config current-context, then inspect the context details before making changes.
Sources and further reading
Use these official references for version-specific command behavior and options.
Found something that needs updating? Send a correction with the page URL and a supporting source.