Kubernetes (K8s) Master Cheat Sheet: kubectl Commands, Pod Debugging & Manifest Architecture
The battle-tested Kubernetes operator reference: essential kubectl commands, decoding CrashLoopBackOff and OOMKilled states, zero-downtime rolling updates, and hardened pod security contexts.
1. kubectl Everyday Essentials & Fast Manifest Scaffolding
kubectl create deployment web-api --image=nginx:alpine --replicas=3 --dry-run=client -o yaml > deployment.yamlGenerates clean declarative Kubernetes Deployment YAML to disk.
kubectl expose deployment web-api --port=80 --target-port=8080 --type=ClusterIP --dry-run=client -o yaml > service.yamlGenerates ClusterIP Service manifest targeting existing deployment.
kubectl config use-context production-cluster
kubectl config set-context --current --namespace=frontendPoints kubectl to the target cluster and locks commands to the active namespace.
2. Pod Emergency Debugging: CrashLoopBackOff & OOMKilled
kubectl debug -it <pod-name> --image=busybox --target=app-containerAttaches an interactive troubleshooting container into the podโs network and process namespace.
3. Hardened Production Pod Architecture
4. Kubernetes Networking & Ingress Controllers
| Service Type | Scope | Description & Best Use Case | Copy |
|---|---|---|---|
| ClusterIP | Internal Only | Default virtual IP reachable only inside the cluster; use for microservices and databases | |
| NodePort | External via Node IP | Exposes static port (30000-32767) on every node; useful for dev clusters or legacy load balancers | |
| LoadBalancer | Public Cloud LB | Provisions native cloud provider load balancer (AWS NLB, GCP LB, Azure LB) | |
| Ingress / Gateway API | HTTP / Layer 7 Router | Routes HTTP/HTTPS hostnames and URI paths to multiple services using a single public IP address |
5. Configuration & Secret Management
kubectl create secret generic db-credentials \
--from-literal=username=postgres \
--from-literal=password="StrongP@ssw0rd2026!" \
--dry-run=client -o yaml > secret.yamlGenerates base64 encoded Kubernetes secret manifest securely.
kubectl rollout restart deployment/hardened-apiGracefully rotates all pods to pick up new ConfigMap or Secret changes with zero downtime.
kubectl rollout status deployment/hardened-apiBlocks until all replacement pods pass readiness probes and old pods terminate.
6. Rapid kubectl Cheat Sheet Table
| Task | Command | Notes | Copy |
|---|---|---|---|
| List pods with Node & IP info | kubectl get pods -o wide | Pods | |
| Sort pods by memory usage | kubectl top pods --sort-by=memory | Monitoring | |
| Sort nodes by CPU utilization | kubectl top nodes --sort-by=cpu | Monitoring | |
| Delete pod forcefully (emergency only) | kubectl delete pod <name> --grace-period=0 --force | Pods | |
| Drain node for maintenance | kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data | Nodes | |
| Uncordon node after reboot | kubectl uncordon <node-name> | Nodes |
Related Free Online Tools
Put these techniques into practice immediately with our privacy-first browser utilities:
Generate accurate 5-token cron expressions for Kubernetes CronJob manifests.
Encode and decode base64 strings for Kubernetes Secret manifests.
Convert Kubernetes YAML configuration files into JSON for Helm or API validation.