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.

Pod & Deployment Operations

Manage and inspect workloads running on your cluster nodes.

CommandDescriptionExample
kubectl get pods -AList all pods across all namespaceskubectl get pods -n production -o wide
kubectl describe pod <name>Show detailed pod lifecycle events and crash reasonskubectl describe pod api-worker-8b2
kubectl logs -f <pod> -c <container>Stream live logs from pod containerkubectl logs -f my-pod --tail 100
kubectl exec -it <pod> -- shOpen interactive shell inside running podkubectl exec -it my-pod -- /bin/bash
kubectl rollout restart deploy/<name>Trigger zero-downtime rolling restart of deploymentkubectl rollout restart deploy/web-api

Port-Forwarding & Cluster Access

Connect your local machine directly to internal Kubernetes cluster services.

CommandDescriptionExample
kubectl port-forward svc/<name> <local>:<remote>Forward local port to internal ClusterIP servicekubectl port-forward svc/postgres 5432:5432
kubectl port-forward pod/<name> <port>Directly forward traffic to an individual podkubectl port-forward redis-0 6379:6379
kubectl config use-context <context>Switch active cluster contextkubectl 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`.