Kubernetes (kubectl), Pods, Deployments & Services Cheat Sheet
Kubernetes schedules your containers into Pods across worker machines, keeps the
desired replica count healthy via Deployments, and exposes them reliably using
Servicesโall controlled through the kubectl CLI.
Anatomy of a kubectl Command
1 Core Kubernetes Objects
Everything in Kubernetes is an API object defined in YAML. Here are the 8 building blocks you will touch every day.
| Object | Short Name | What It Does (Plain English) |
|---|---|---|
Pod |
po |
Smallest deployable unit; wraps 1+ tightly coupled containers sharing an IP and volumes. |
Deployment |
deploy |
Manages stateless Pods: handles rolling updates, scaling replicas, and rollbacks. |
ReplicaSet |
rs |
Ensures a fixed number of identical Pod copies stay running (managed by Deployment). |
Service |
svc |
Provides a stable virtual IP & DNS name that load-balances across ephemeral Pods. |
ConfigMap |
cm |
Stores non-sensitive configuration (env vars, config files) separate from images. |
Secret |
secret |
Stores sensitive values (passwords, API keys, TLS certs) mounted as env vars or files. |
Ingress |
ing |
HTTP/HTTPS router that maps external domains/paths (/api) to Services.
|
Namespace |
ns |
Virtual cluster partition (e.g., dev, staging,
prod) for isolation. |
2 kubectl Inspection & Debugging
When a Pod refuses to start or crashes, follow the golden triage loop: get โ
describe โ logs โ exec.
kubectl get pods -A -o wide-A shows all namespaces; -o wide reveals the Pod IP and
which Worker Node it runs on.
kubectl describe pod <pod> -n <ns>ImagePullBackOff, failed probes, or scheduling blocks.
kubectl logs -f --previous <pod>--previous grabs logs from the container instance that just crashed in
CrashLoopBackOff. Drop --previous for live logs.
kubectl exec -it <pod> -- sh-- to separate kubectl flags from the container command
(sh or bash).
kubectl top pods --sort-by=memoryOOMKilled
crash.
kubectl get events --sort-by='.metadata.creationTimestamp'
3 Services & Networking
Pod IPs change every time a Pod restarts. A Service gives your Pods a permanent
internal DNS name (<service>.<namespace>.svc.cluster.local) and routes
traffic by label selector.
| Service Type | Who Can Reach It? | Typical Use Case |
|---|---|---|
ClusterIP (default) |
Only Pods inside the cluster. | Internal APIs, Redis, PostgreSQL databases. |
NodePort |
External traffic via <NodeIP>:30000โ32767. |
Local clusters (Minikube/kind) or custom external LBs. |
LoadBalancer |
Public internet via cloud LB (AWS ELB, GCP LB). | Production web apps or Ingress Controllers. |
kubectl port-forward svc/<svc> 8080:80http://localhost:8080 without
exposing it publicly.
kubectl get svc,ep -n <ns>ENDPOINTS is <none>, your Service
selector labels don't match your Pod labels.
4 Deployments, Scaling & Rollbacks
Never create bare Pods in productionโalways wrap them in a Deployment so Kubernetes can replace failed Pods and perform zero-downtime rolling updates.
apply -f โ watch
rollout status โ if broken, hit rollout undo. You never manually delete
old Pods during a release; the Deployment controller swaps them gradually.
kubectl apply -f deployment.yamlkubectl scale deploy/<name> --replicas=5kubectl rollout status deploy/<name>kubectl rollout undo deploy/<name>5 Danger Zone & Beginner Traps
kubectl delete ns <namespace> Wipes Everything Inside
Deleting a Namespace cascades and immediately destroys every Pod, Deployment, Service, Secret, ConfigMap, and PersistentVolumeClaim inside it. Always double-check the namespace name.
requests & limits
Without resource requests and limits in your Pod spec, one
runaway container can starve an entire Worker Node and trigger cluster-wide
OOMKilled evictions.
CrashLoopBackOff Without Checking --previous
Logs
Running plain kubectl logs <pod> on a restarting Pod often returns an
empty or half-booted log. Always add --previous to see the actual error
that killed the last container.
If you switch between minikube, staging, and
prod, verify your target first with
kubectl config current-context before running apply or
delete.