Cloud & DevOps

Kubernetes Commands Cheat Sheet

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

Kubernetes operations console with an orchestrated cluster of nodes and pods
Original concept artwork created for this Circuit Compass guide.

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-contextShow the active cluster context.
kubectl config get-contextsList available contexts.
kubectl get namespacesList namespaces.
kubectl api-resourcesList resource types supported by the server.
kubectl versionShow client and server version information.

Inspect workloads

kubectl get pods -n NAMEList pods in a namespace.
kubectl get deploy,svc -n NAMEList deployments and services.
kubectl describe pod POD -n NAMEShow status, events and configuration.
kubectl logs POD -n NAMERead container logs.
kubectl logs POD --previous -n NAMERead logs from the previous crashed container.

Apply, scale and roll out

kubectl diff -f FILEPreview declarative changes.
kubectl apply -f FILEApply configuration.
kubectl scale deploy/APP --replicas=3Change replica count.
kubectl rollout status deploy/APPWatch rollout progress.
kubectl rollout undo deploy/APPRoll 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.

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

Features, software and prices change. Confirm current details with these sources before making a decision.

Found something that needs updating? Send a correction with the page URL and a supporting source.