Cloud & ContainersUpdated: 2026-11-07
The Ultimate kubectl Pod Debugging, Rollouts & Cluster Reference
Quick copy-paste syntax for inspecting crashing pods, tailing container logs, triggering rolling restarts, and managing Kubernetes namespaces.
Kubernetes (K8s) is the industry standard container orchestration platform. From troubleshooting CrashLoopBackOff container states to executing zero-downtime rolling deployments, this cheat sheet compiles daily production kubectl commands.
Table of Contents
Pod Inspection & Debugging Commands
Diagnosing crashing pods, memory limits, and streaming live logs.
| Operation | Command Syntax | Description |
|---|---|---|
| Follow Pod Logs | `kubectl logs -f pod-name -n production --tail=100` | Streams the last 100 log lines from active container in real time. |
| Inspect Pod Events | `kubectl describe pod pod-name -n production` | Reveals OOMKilled errors, failed probes, and image pull failures. |
| Interactive Debug Shell | `kubectl exec -it pod-name -n production -- /bin/sh` | Opens interactive shell inside live running container. |
| Port-Forward to Localhost | `kubectl port-forward svc/api-service 8080:80 -n production` | Tunnels cluster service directly to your local computer port 8080. |
Deployments & Rolling Restarts
Managing deployment rollouts and scaling replica sets.
| Management Task | Command Syntax | Behavior |
|---|---|---|
| Zero-Downtime Restart | `kubectl rollout restart deployment/api-deploy -n prod` | Triggers graceful rolling restart of all pods without downtime. |
| Rollout Status Check | `kubectl rollout status deployment/api-deploy -n prod` | Blocks terminal until all new revision pods are healthy. |
| Scale Replicas | `kubectl scale deployment/api-deploy --replicas=5 -n prod` | Dynamically scales running pod count up or down. |
Frequently Asked Questions
What causes a pod to enter CrashLoopBackOff in Kubernetes?
Common causes include application runtime exceptions (missing environment variable), container running out of memory (OOMKilled), or failing liveness/readiness probes.
How do I view resource consumption (CPU and Memory) across pods?
Run `kubectl top pods -n namespace` (requires Metrics Server installed in the cluster).