Kubernetes Debugging Cheat Sheet

Core kubectl troubleshooting commands for pods, deployments, services, events, logs, exec sessions, and ephemeral debugging.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Cluster Triage
Check kubectl and server version
kubectl version --short

# Show client and server version details.

Show cluster endpoints
kubectl cluster-info

# Display the control plane and addon URLs known to kubectl.

List nodes
kubectl get nodes

# Quickly see whether nodes are Ready.

List nodes with details
kubectl get nodes -o wide

# Show node IPs, versions, and roles.

List all major resources
kubectl get all -A

# Quick cluster-wide snapshot across namespaces.

List resource types
kubectl api-resources

# See which resource kinds the API server exposes.

Dump cluster diagnostic info
kubectl cluster-info dump

# Collect broad cluster state for troubleshooting.

## Pods and Workloads
List pods across all namespaces
kubectl get pods -A

# Find failing pods anywhere in the cluster.

List pods with node and IP
kubectl get pods -A -o wide

# Show placement and pod IP information.

Get full pod YAML
kubectl get pod <pod> -n <namespace> -o yaml

# Inspect raw spec and status fields.

Describe a pod
kubectl describe pod <pod> -n <namespace>

# Read conditions, events, mounts, image pulls, and restarts.

List deployments
kubectl get deployments -A

# Find workloads with rollout or availability issues.

Describe a deployment
kubectl describe deployment <name> -n <namespace>

# Inspect replica counts, rollout conditions, and selector details.

Check rollout status
kubectl rollout status deployment/<name> -n <namespace>

# Wait for or inspect deployment rollout progress.

List ReplicaSets
kubectl get rs -n <namespace>

# See which ReplicaSet a rollout created and whether scaling succeeded.

List StatefulSets
kubectl get statefulsets -A

# Inspect ordered pod creation and update status.

Describe a Job
kubectl describe job <name> -n <namespace>

# Inspect failures, completions, and backoff behavior.

## Events and Conditions
List events in a namespace
kubectl get events -n <namespace>

# See recent warnings and scheduling errors.

Sort events by time
kubectl get events -n <namespace> --sort-by=.metadata.creationTimestamp

# Show oldest to newest event timestamps for a namespace.

Sort cluster-wide events by time
kubectl get events -A --sort-by=.metadata.creationTimestamp

# Helpful for cluster-wide incident triage.

Wait for pod readiness
kubectl wait --for=condition=Ready pod/<pod> -n <namespace> --timeout=60s

# Use readiness conditions to gate troubleshooting steps or scripts.

List pod phase and reason
kubectl get pods -n <namespace> -o custom-columns=NAME:.metadata.name,PHASE:.status.phase,REASON:.status.containerStatuses[0].state.waiting.reason

# Compact custom columns view for triage.

## Logs, Exec, and Ephemeral Debugging
Read pod logs
kubectl logs <pod> -n <namespace>

# Print logs from a single-container pod.

Read logs from a specific container
kubectl logs <pod> -n <namespace> -c <container>

# Required for multi-container pods.

Stream logs
kubectl logs -f <pod> -n <namespace>

# Follow logs live while reproducing an issue.

Read previous container logs
kubectl logs <pod> -n <namespace> -p

# Useful after restarts or CrashLoopBackOff.

Read logs for pods matching a label
kubectl logs -n <namespace> -l app=<label> --all-containers=true --prefix

# Aggregate logs from a workload set.

Open a shell in a running container
kubectl exec -it <pod> -n <namespace> -- /bin/sh

# Run commands inside a pod for live inspection.

Inspect environment variables
kubectl exec <pod> -n <namespace> -- env

# Quickly validate environment and injected secrets names.

Copy a file from a pod
kubectl cp <namespace>/<pod>:/path/in/pod ./local-file

# Pull logs or generated files out of a running container.

Attach an ephemeral debug container
kubectl debug -it <pod> -n <namespace> --image=busybox:1.36 --target=<container>

# Launch a temporary debugging container in an existing pod.

Create a copy of a pod for debugging
kubectl debug <pod> -n <namespace> --copy-to=<pod>-debug --container=debugger --image=busybox:1.36 -it

# Duplicate a pod and add a debug container or different command.

Port-forward to a pod
kubectl port-forward pod/<pod> -n <namespace> 8080:80

# Reach a pod locally without exposing a Service.

## JSONPath and Useful One-Liners
List pods with restart counts
kubectl get pods -A -o custom-columns=NS:.metadata.namespace,POD:.metadata.name,RESTARTS:.status.containerStatuses[*].restartCount

# Spot frequently restarting containers quickly.

Show which node each pod runs on
kubectl get pods -A -o custom-columns=NS:.metadata.namespace,POD:.metadata.name,NODE:.spec.nodeName

# Correlate pod failures with node placement.

List images used by all pods
kubectl get pods -A -o jsonpath='{..image}' | tr -s '[[:space:]]' '
' | sort | uniq -c

# Find image tags currently running in the cluster.

Show not-ready pods
kubectl get pods -A --field-selector=status.phase!=Running

# Filter pods whose Ready condition is false or missing.

Show pod CPU and memory usage
kubectl top pods -A

# Requires metrics-server; useful for resource-based incidents.

Show node CPU and memory usage
kubectl top nodes

# Identify hot or memory-constrained nodes.

Recommended next

No recommendations yet.