The Kubernetes cheatsheet covers kubectl commands for pod management, deployments, services, configurations, namespaces, and context switching. Includes ready-to-use YAML specs for common resources.
No results found
How to Use This Kubernetes Cheatsheet
Kubernetes (K8s) is the industry-standard container orchestration platform. This cheatsheet covers the most-used kubectl commands for daily cluster operations, from pod inspection to deployment management and context switching.
Pod Inspection
Use kubectl get pods -n namespace to list pods in a namespace. Add -o wide for node assignments, or -o yaml for full spec. Use kubectl describe pod name to see events and status — invaluable for debugging CrashLoopBackOff and ImagePullBackOff errors.
Debugging Workflows
The most common debugging sequence: kubectl get pods → find failing pod → kubectl describe pod name → check Events section → kubectl logs pod-name --previous → fix root cause. For interactive debugging, kubectl exec -it pod-name -- /bin/sh opens a shell inside the container.
Declarative vs Imperative
Always prefer kubectl apply -f manifest.yaml over imperative commands in production. Apply is idempotent and tracks last-applied configuration, making it safe to re-run. Use kubectl diff -f manifest.yaml to preview changes before applying them.
Frequently Asked Questions
Is this Kubernetes cheatsheet free?
Yes, completely free with no signup. All kubectl commands and YAML examples are copyable.
How do I view logs for a specific container in a pod?
Use kubectl logs pod-name -c container-name to view logs for a specific container. Add -f to follow (tail) the logs in real time. For previous container instance logs (e.g., after a crash), use --previous flag.
What is the difference between kubectl apply and kubectl create?
kubectl apply is declarative — it creates or updates resources by merging the desired state from your YAML file. kubectl create is imperative — it only creates resources and fails if they already exist. Use apply for idempotent GitOps workflows.
How do I switch between Kubernetes clusters?
Use kubectl config use-context context-name to switch contexts. List all available contexts with kubectl config get-contexts. The current context is marked with an asterisk.
What is the difference between a ConfigMap and a Secret?
Both store configuration data as key-value pairs, but Secrets are base64-encoded and intended for sensitive data (passwords, tokens, TLS certs). ConfigMaps are for non-sensitive config. Secrets can be mounted as files or exposed as env vars just like ConfigMaps.
How do I scale a deployment?
Use kubectl scale deployment my-app --replicas=5 for quick scaling. For persistent changes, update the replicas field in the Deployment YAML and run kubectl apply. For autoscaling based on CPU/memory, use kubectl autoscale deployment.