kubectl commands cheatsheet.
Inspect, debug, deploy and scale — the kubectl commands you reach for on any cluster. Tap to copy.
kubectl get podsList pods in the current namespacekubectl get pods -AList pods across all namespaceskubectl get svcList serviceskubectl get nodesList cluster nodeskubectl get deploymentsList deploymentskubectl describe pod <name>Show detailed info and events for a podkubectl logs <pod>Print a pod's logskubectl logs -f <pod>Stream a pod's logs livekubectl exec -it <pod> -- bashOpen a shell inside a podkubectl port-forward <pod> 8080:80Forward a local port to a podkubectl top podsShow CPU and memory usage per podkubectl apply -f <file>.yamlCreate or update resources from a filekubectl delete -f <file>.yamlDelete the resources defined in a filekubectl delete pod <name>Delete a podkubectl scale deploy <name> --replicas=3Scale a deployment to N replicaskubectl rollout restart deploy <name>Restart a deployment's podskubectl config get-contextsList available cluster contextskubectl config use-context <name>Switch the active cluster contextkubectl get nsList namespaceskubectl config set-context --current --namespace=<ns>Set the default namespaceThe everyday kubectl loop
For all its reputation, day-to-day Kubernetes runs on a handful of verbs. kubectl get lists what exists (pods, services, deployments), kubectl describe shows the full detail and recent events for one thing, and kubectl apply -f ships changes from a YAML file. Getting comfortable with get and describe alone covers most of what you do in a cluster, because they answer the two questions you ask constantly: what's running, and why isn't it healthy?
Debugging pods
When something's broken, two commands do the heavy lifting. kubectl logs <pod> prints a pod's output (add -f to follow it live, like tailing a log), and kubectl exec -it <pod> -- sh opens a shell inside the running container so you can look around from the inside. kubectl get events often reveals the real reason a pod won't start — image pull failures, resource limits, failed health checks — when the pod status alone is cryptic.
Mind your context and namespace
The mistake that bites everyone at least once: running a command against the wrong cluster or namespace. kubectl config get-contexts shows which cluster you're pointed at, and most commands default to your current namespace unless you add -n <namespace>. Before anything that changes state, it's worth a half-second to confirm where you are — an apply or delete against production when you meant staging is a bad afternoon. These pair naturally with the Docker and cloud CLI commands.