All cheatsheets

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.

0 / 4 updated
podv1
Ready
podv1
Ready
podv1
Ready
podv1
Ready

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.

Loading 3D…

31 entries

Pods & workloads10

kubectl get pods -A

List pods across all namespaces

kubectl get pods -o wide

Pods with node, IP, and nominated-node details

kubectl describe pod <name>

Detailed pod info: conditions, events, mounts, limits

kubectl get pod <name> -o yaml

Full YAML spec of a running pod

kubectl logs -f <pod>

Stream a pod's logs in real time

kubectl logs <pod> -c <container> --previous

Logs from the most recently terminated container instance

kubectl exec -it <pod> -- sh

Open 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=3

Scale a deployment to N replicas

Apply & manage6

kubectl apply -f file.yaml

Declaratively create or update resources from a file

kubectl apply -k ./overlay

Apply a kustomize overlay

kubectl delete -f file.yaml

Delete the resources defined in a manifest

kubectl get <res> -o yaml

Print 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: 8080

Production-ready Deployment + ClusterIP Service template

Networking & config6

kubectl port-forward svc/<name> 8080:80

Tunnel a local port directly to a Service or Pod

kubectl get svc

List services in the current namespace

kubectl get ingress

List ingresses

kubectl get cm,secret

List ConfigMaps and Secrets

kubectl create secret generic s --from-literal=k=v

Create a secret from a literal value

kubectl get secret s -o jsonpath='{.data.k}' | base64 -d

Decode a base64-encoded secret value

Contexts & namespaces6

kubectl config get-contexts

List 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 pod

Pod CPU/memory usage (requires metrics-server)

kubectl get events --sort-by=.lastTimestamp

Recent cluster events sorted by time

kubectl debug -it <pod> --image=busybox

Attach an ephemeral debug container to a running pod

Debugging common failures3

# Diagnose CrashLoopBackOff

A container keeps crashing; Kubernetes backs off restart timing exponentially

# Diagnose Pending pod

A pod stays in Pending and never starts

# Resource requests and limits

CPU/memory requests (scheduling) vs limits (enforcement)