Cheatsheets
kubectl
Common Kubernetes commands for pods, deployments, networking, and contexts.
Visualize
Rolling update
A new pod goes Ready before an old one is removed — zero downtime.
Rolling update: a new pod becomes Ready before an old one is removed (maxSurge=1, maxUnavailable=0) → zero downtime. kubectl rollout status to watch, kubectl rollout undo to revert.
Kubernetes — scheduling & rolling update (3D)
The scheduler spreads replicas across nodes; a rolling update swaps v1→v2 one at a time; a failed node reschedules its pods.
31 entries
Pods & workloads10
kubectl get pods -AList pods across all namespaces
kubectl get pods -o widePods with node, IP, and nominated-node details
kubectl describe pod <name>Detailed pod info: conditions, events, mounts, limits
kubectl get pod <name> -o yamlFull YAML spec of a running pod
kubectl logs -f <pod>Stream a pod's logs in real time
kubectl logs <pod> -c <container> --previousLogs from the most recently terminated container instance
kubectl exec -it <pod> -- shOpen an interactive shell inside a running container
kubectl rollout status deploy/<name>Wait for a deployment rollout to complete
kubectl rollout undo deploy/<name>Roll back to the previous deployment revision
kubectl scale deploy/<name> --replicas=3Scale a deployment to N replicas
Apply & manage6
kubectl apply -f file.yamlDeclaratively create or update resources from a file
kubectl apply -k ./overlayApply a kustomize overlay
kubectl delete -f file.yamlDelete the resources defined in a manifest
kubectl get <res> -o yamlPrint the full live YAML of any resource
kubectl explain <res>Show the schema and docs for any resource field
# Minimal Deployment + ClusterIP Service
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myrepo/api:1.2.3 # pin to a digest in prod
ports:
- containerPort: 8080
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: api
namespace: default
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8080Production-ready Deployment + ClusterIP Service template
Networking & config6
kubectl port-forward svc/<name> 8080:80Tunnel a local port directly to a Service or Pod
kubectl get svcList services in the current namespace
kubectl get ingressList ingresses
kubectl get cm,secretList ConfigMaps and Secrets
kubectl create secret generic s --from-literal=k=vCreate a secret from a literal value
kubectl get secret s -o jsonpath='{.data.k}' | base64 -dDecode a base64-encoded secret value
Contexts & namespaces6
kubectl config get-contextsList all kubeconfig contexts
kubectl config use-context <name>Switch the active context (cluster + credentials)
kubectl config set-context --current --namespace=<ns>Set the default namespace for the current context
kubectl top podPod CPU/memory usage (requires metrics-server)
kubectl get events --sort-by=.lastTimestampRecent cluster events sorted by time
kubectl debug -it <pod> --image=busyboxAttach an ephemeral debug container to a running pod
Debugging common failures3
# Diagnose CrashLoopBackOffA container keeps crashing; Kubernetes backs off restart timing exponentially
# Diagnose Pending podA pod stays in Pending and never starts
# Resource requests and limitsCPU/memory requests (scheduling) vs limits (enforcement)