kubectl Cheat Sheet
A reference for kubectl and Kubernetes, viewing pods and nodes, applying and deleting manifests, scaling and rolling out, reading logs, opening a shell, and forwarding ports.
A quick reference to kubectl, the Kubernetes command-line client. Replace
NAME, NS, and deploy/app with your own. Add
-n NS to any command to target a namespace, or -A for all.
Context & config
| Command | What it does |
|---|---|
kubectl config get-contexts | List your configured contexts |
kubectl config use-context NAME | Switch the active context |
kubectl config set-context --current --namespace=NS | Set the default namespace for the current context |
kubectl cluster-info | Show the control plane address |
View resources
| Command | What it does |
|---|---|
kubectl get pods -A | List pods across all namespaces |
kubectl get pods -o wide | List pods with node and IP detail |
kubectl describe pod NAME | Show events and full detail for a pod |
kubectl get nodes | List cluster nodes |
kubectl get all -n NS | Show the main resource types in a namespace |
Apply & delete
| Command | What it does |
|---|---|
kubectl apply -f file.yaml | Create or update resources from a manifest |
kubectl apply -k ./overlay | Apply a Kustomize directory |
kubectl delete -f file.yaml | Delete the resources defined in a file |
kubectl delete pod NAME | Delete a single pod (it may be recreated) |
kubectl scale deploy/NAME --replicas=3 | Set a deployment's replica count |
Logs & exec
| Command | What it does |
|---|---|
kubectl logs NAME | Print a pod's logs |
kubectl logs -f NAME | Follow the logs as they arrive |
kubectl logs NAME --previous | Show logs from the previous (crashed) container |
kubectl exec -it NAME -- sh | Open an interactive shell in a pod |
kubectl port-forward svc/NAME 8080:80 | Forward a local port to a service |
Rollouts
| Command | What it does |
|---|---|
kubectl rollout status deploy/NAME | Watch a rollout until it finishes |
kubectl rollout undo deploy/NAME | Roll a deployment back to the last revision |
kubectl rollout history deploy/NAME | List a deployment's revision history |
kubectl set image deploy/NAME app=img:tag | Update a container image (triggers a rollout) |
Tip: install kubectl autocomplete for your shell, alias it to
k, and prefer declarative apply -f over imperative commands so your
cluster state lives in version control.
What this does
A kubectl cheat sheet covers viewing pods and nodes, applying and deleting manifests, scaling and rolling out, reading logs, opening a shell, and forwarding ports.
How to use it
- Browse by section.
- Find the command you need.
- Copy it with one tap.
- Replace the pod, deployment, and namespace.
Example
kubectl get pods -A lists every pod across all namespaces.
Sources & methodology
Last updated .
Frequently asked questions
Imperative or declarative — which should I use?
Prefer declarative kubectl apply -f with manifests stored in version control. Use imperative commands like run or expose for quick experiments, not for production setups.
How do I switch namespace or context?
Add -n NAMESPACE to any command, or use kubectl config set-context --current --namespace=NAMESPACE to change the default for the current context.
How do I debug a crashing pod?
Run kubectl describe pod NAME for events, then kubectl logs NAME (add --previous for the last crashed instance). kubectl get events --sort-by=.lastTimestamp shows cluster-wide activity.
Related tools
Git Cheat Sheet
The Git commands you use every day, setup, the add/commit/push workflow, branching and merging, working with remotes, and undoing mistakes safely.
Docker Cheat Sheet
A reference for everyday Docker, building and tagging images, running and managing containers, ports and volumes, system cleanup, and Docker Compose.
Vim Cheat Sheet
A reference for the Vim editor, modes, moving around, editing, search and replace, and saving or quitting, including the escape hatch for when you are stuck.
Regex Cheat Sheet
A regular-expression reference, character classes, anchors, quantifiers, groups and alternation, lookarounds, common ready-made patterns, and flags.