Kubernetes & DevOps ReferenceUpdated: 2026-11-06
Kubernetes (kubectl) CLI Reference for Pods, Services & Deployments
Quick lookup for cluster debugging, pod logs, rollout status, port-forwarding, and secret management.
The kubectl command line tool controls the Kubernetes cluster manager. From inspecting why a pod is stuck in CrashLoopBackOff to port-forwarding internal database services, this reference sheet provides production-tested kubectl commands.
Table of Contents
Pod & Deployment Operations
Manage and inspect workloads running on your cluster nodes.
| Command | Description | Example |
|---|---|---|
| kubectl get pods -A | List all pods across all namespaces | kubectl get pods -n production -o wide |
| kubectl describe pod <name> | Show detailed pod lifecycle events and crash reasons | kubectl describe pod api-worker-8b2 |
| kubectl logs -f <pod> -c <container> | Stream live logs from pod container | kubectl logs -f my-pod --tail 100 |
| kubectl exec -it <pod> -- sh | Open interactive shell inside running pod | kubectl exec -it my-pod -- /bin/bash |
| kubectl rollout restart deploy/<name> | Trigger zero-downtime rolling restart of deployment | kubectl rollout restart deploy/web-api |
Port-Forwarding & Cluster Access
Connect your local machine directly to internal Kubernetes cluster services.
| Command | Description | Example |
|---|---|---|
| kubectl port-forward svc/<name> <local>:<remote> | Forward local port to internal ClusterIP service | kubectl port-forward svc/postgres 5432:5432 |
| kubectl port-forward pod/<name> <port> | Directly forward traffic to an individual pod | kubectl port-forward redis-0 6379:6379 |
| kubectl config use-context <context> | Switch active cluster context | kubectl config use-context prod-us-east |
Interactive Client-Side Tools for this Guide
Test and run these patterns directly inside your browser with zero server uploads:
Frequently Asked Questions
How do I debug a pod stuck in CrashLoopBackOff?
First run `kubectl logs <pod-name> --previous` to see why the previous container crashed, followed by `kubectl describe pod <pod-name>` to inspect OOMKilled events or missing environment variables.
How do I generate a Kubernetes YAML template quickly?
Use dry-run: `kubectl create deploy web --image=nginx --dry-run=client -o yaml > deployment.yaml`.