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

CommandWhat it does
kubectl config get-contextsList your configured contexts
kubectl config use-context NAMESwitch the active context
kubectl config set-context --current --namespace=NSSet the default namespace for the current context
kubectl cluster-infoShow the control plane address

View resources

CommandWhat it does
kubectl get pods -AList pods across all namespaces
kubectl get pods -o wideList pods with node and IP detail
kubectl describe pod NAMEShow events and full detail for a pod
kubectl get nodesList cluster nodes
kubectl get all -n NSShow the main resource types in a namespace

Apply & delete

CommandWhat it does
kubectl apply -f file.yamlCreate or update resources from a manifest
kubectl apply -k ./overlayApply a Kustomize directory
kubectl delete -f file.yamlDelete the resources defined in a file
kubectl delete pod NAMEDelete a single pod (it may be recreated)
kubectl scale deploy/NAME --replicas=3Set a deployment's replica count

Logs & exec

CommandWhat it does
kubectl logs NAMEPrint a pod's logs
kubectl logs -f NAMEFollow the logs as they arrive
kubectl logs NAME --previousShow logs from the previous (crashed) container
kubectl exec -it NAME -- shOpen an interactive shell in a pod
kubectl port-forward svc/NAME 8080:80Forward a local port to a service

Rollouts

CommandWhat it does
kubectl rollout status deploy/NAMEWatch a rollout until it finishes
kubectl rollout undo deploy/NAMERoll a deployment back to the last revision
kubectl rollout history deploy/NAMEList a deployment's revision history
kubectl set image deploy/NAME app=img:tagUpdate 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

  1. Browse by section.
  2. Find the command you need.
  3. Copy it with one tap.
  4. 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.