This is a complete, hands-on Kubernetes cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.
Kubernetes is a container orchestrator: you declare the desired state of your workloads in YAML and controllers continuously reconcile the cluster toward it, handling scheduling, scaling, healing and networking.
Why you reach for it
- Self-healing: crashed pods are restarted and rescheduled automatically
- Declarative rollouts and rollbacks instead of hand-run deploy scripts
- A portable API that runs the same on EKS, AKS, GKE and on-prem
Installation
# Spin up a local cluster with kind, then talk to it with kubectl
kind create cluster --name dev
kubectl cluster-info --context kind-dev
kubectl get nodesConfiguration reference
A Deployment plus Service with probes and resource limits.
apiVersion: apps/v1
kind: Deployment
metadata: { name: web }
spec:
replicas: 3
selector: { matchLabels: { app: web } }
template:
metadata: { labels: { app: web } }
spec:
containers:
- name: web
image: ghcr.io/acme/web:1.0
ports: [{ containerPort: 3000 }]
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { cpu: 500m, memory: 256Mi }
readinessProbe:
httpGet: { path: /healthz, port: 3000 }
---
apiVersion: v1
kind: Service
metadata: { name: web }
spec:
selector: { app: web }
ports: [{ port: 80, targetPort: 3000 }]Core commands you use daily
kubectl apply -f deploy.yaml
kubectl rollout status deploy/web
kubectl get pods -l app=web
kubectl logs deploy/web
kubectl rollout undo deploy/web # roll back the last changeInspect
kubectl get pods -A -o wide
kubectl describe pod web-abc123
kubectl logs -f deploy/web --all-containers
kubectl top pods
kubectl get events --sort-by=.lastTimestampDebug
kubectl exec -it deploy/web -- sh
kubectl port-forward svc/web 8080:80
kubectl debug -it pod/web --image=busybox --target=web
kubectl get pod web -o yaml | lessManage & roll out
kubectl apply -f .
kubectl scale deploy/web --replicas=5
kubectl rollout status deploy/web
kubectl rollout undo deploy/web
kubectl label pod web tier=frontend --overwriteContexts & namespaces
kubectl config get-contexts
kubectl config use-context prod
kubectl config set-context --current --namespace=webUse it in CI/CD
Set the new image and wait for the rollout inside a pipeline.
deploy:
stage: deploy
script:
- kubectl set image deploy/web web=ghcr.io/acme/web:$CI_COMMIT_SHA
- kubectl rollout status deploy/web --timeout=120s
rules:
- if: '$CI_COMMIT_BRANCH == "main"'Best-practice checklist
- Set requests/limits and use the HorizontalPodAutoscaler for elastic workloads
- Separate config (ConfigMap) from secrets and mount them, don't bake them in
- Use readiness probes to gate traffic and PodDisruptionBudgets for safe drains
- Adopt GitOps (ArgoCD/Flux) so the cluster state lives in reviewed Git
Common pitfalls to avoid
- No resource requests/limits - the scheduler can't pack pods and OOM kills surprise you
- Using :latest images so rollbacks and caching become unpredictable
- Liveness probes that are too aggressive, restarting healthy-but-slow pods
- Treating Secrets as encrypted - they are only base64-encoded at rest by default
Security quick wins
- Enforce least privilege with RBAC and disable the default ServiceAccount token mount
- Apply NetworkPolicies to default-deny east-west traffic
- Run Pod Security Admission in 'restricted' mode and scan workloads with Trivy
Works well with
- Docker - Package an app and its dependencies into a portable image that runs the same everywhere.
- Helm - The package manager for Kubernetes - template, version and release your manifests as charts.
- Argo CD - GitOps continuous delivery for Kubernetes - Git is the source of truth, the cluster is reconciled to match.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.
Want senior help putting Kubernetes to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.