← Back to cheat sheets

Containers & Orchestration

Kubernetes cheat sheet

Kubernetes orchestrates containerized applications at scale.

On this page

Table of contents

Use this page for fast recall. Use Full documentation when you want the complete end-to-end path.

Quick workflow

A simple 5-step flow you can follow when using Kubernetes in real work.

1) Setup

Install/run the tool and confirm version. Create a minimal config.

2) Small change

Do one small action end-to-end to prove the workflow.

3) Validate

Check output, logs, and status. Catch mistakes early.

4) Automate

Convert it into a repeatable script or pipeline step.

5) Productionize

Add safety: secrets, rollback, observability, and docs.

Workflows you will actually reuse

These are practical sequences you can copy into your own checklist or runbook.

CrashLoopBackOff debugging

Goal: Identify why the container is restarting and fix the real root cause.

- Describe the pod and read events (probe failures, image pull, OOM).

- Read logs (use `-c` for multi-container pods).

- Check environment variables and mounted config/secrets.

- Validate readiness/liveness probes.

- Roll forward a fix, or rollback safely if needed.

Key Concepts

- Pods

- Deployments

- Services

Learning path (high-level):

- Core objects

- Production deployments

- Troubleshooting

Quick Start

Check cluster

Command

kubectl cluster-info

Apply manifest

Command

kubectl apply -f deployment.yaml

Watch pods

Command

kubectl get pods -w

Common Commands

Short descriptions and practical intent. Search, filter, copy, and reuse.

Showing 25

Basics
kubectl version --client

Show kubectl version.

Basics
kubectl config get-contexts

List contexts.

Basics
kubectl config current-context

Show current context.

Basics
kubectl config use-context <ctx>

Switch cluster context.

Namespaces
kubectl get ns

List namespaces.

Discover
kubectl get all -n default

List core resources in namespace.

Discover
kubectl get pods -n <ns> -o wide

Pods with nodes/IPs.

Discover
kubectl get deploy -n <ns>

List deployments.

Discover
kubectl get svc -n <ns>

List services.

Deploy
kubectl apply -f k8s.yaml

Apply manifests (create/update).

Deploy
kubectl delete -f k8s.yaml

Delete resources from manifest.

Deploy
kubectl rollout status deploy/<name> -n <ns>

Check rollout progress.

Deploy
kubectl rollout history deploy/<name> -n <ns>

Show rollout history.

Deploy
kubectl rollout undo deploy/<name> -n <ns>

Rollback to previous revision.

Debug
kubectl describe pod <pod> -n <ns>

Detailed pod info and events.

Debug
kubectl get events -n <ns> --sort-by=.metadata.creationTimestamp

Namespace events (time-sorted).

Debug
kubectl logs <pod> -n <ns>

Read pod logs.

Debug
kubectl logs -f <pod> -n <ns>

Follow logs.

Debug
kubectl logs <pod> -c <container> -n <ns>

Logs for a specific container.

Debug
kubectl exec -it <pod> -n <ns> -- sh

Open pod shell.

Debug
kubectl port-forward svc/<svc> 8080:80 -n <ns>

Forward local port to service.

Deploy
kubectl set image deploy/<name> <container>=repo/img:tag -n <ns>

Update container image.

Operate
kubectl scale deploy/<name> --replicas=3 -n <ns>

Scale deployment.

Operate
kubectl top pods -n <ns>

Pod CPU/mem (metrics server).

Operate
kubectl top nodes

Node CPU/mem (metrics server).

Copyable snippets

Small blocks you can drop into your terminal, config, or runbook.

Common triage sequence

bash

kubectl get pods -n <ns>
kubectl describe pod <pod> -n <ns>
kubectl logs <pod> -n <ns> --tail=200

Troubleshooting checklist

When things break, follow this order to stay calm and move fast.

- If pods are Pending: check node capacity, taints/tolerations, and PVC binding events.

- If ImagePullBackOff: verify image name/tag, registry access, and imagePullSecrets.

- If 503/traffic issues: check Service selectors, endpoints, and readiness probes.

- If rollouts flap: check probes, resource limits, and startup time.

Pitfalls

The common mistakes that slow people down when using Kubernetes.

- Debugging only with `kubectl get` and ignoring `describe`/events.

- Missing resource requests/limits and breaking node stability.

- No readiness/liveness probes leading to broken rollouts.

Mini lab (practice)

Do these tasks in order. You will feel the tool instead of just reading about it.

- Deploy a simple app, expose it with a Service, and port-forward to test locally.

- Break the deployment (wrong image) and debug using `describe`, `events`, and `logs`.

- Practice a rollback using rollout history and undo.

Interview prompts

Use these to test if you truly understand the basics (and can explain them clearly).

- Explain Deployments, ReplicaSets, and Pods.

- How do you debug CrashLoopBackOff?

- What’s the difference between ClusterIP, NodePort, and LoadBalancer services?

Official Docs

https://kubernetes.io/docs/home/