Kubernetes on call: 5 failures you will meet, and the exact kubectl fixes

· DevOps · Kubernetes

Your phone buzzes at 3 a.m.

Something in the cluster is broken. Users have noticed. You have a terminal and a few minutes.

After years of running Kubernetes in production, I’ve found that most incidents are one of five familiar failures. Each one has a short list of commands that tells you what’s wrong, and another that fixes it.

Here they are.

Prefer to watch? Here’s the video version:

First: hear it before your users do

The best incident is the one an alert tells you about first.

If you run Prometheus with kube-state-metrics, two alerts catch most of what follows:

Send them to Slack. Send the important ones to a phone.

Then, when the alert fires, start here:

kubectl get pods -n shop

The STATUS and RESTARTS columns usually tell you which of the five you’re facing.

1. OOMKilled: the container ran out of memory

The analogy: a container is a tenant in a flat with a fixed size. Bring in more furniture than fits, and the landlord doesn’t negotiate. The whole tenant gets thrown out.

The symptom: the pod restarts again and again.

kubectl describe pod checkout-7d9f8 -n shop

Look for this under Last State:

Last State:  Terminated
  Reason:    OOMKilled
  Exit Code: 137

Exit code 137 means the process was killed with signal 9 (128 + 9). The kernel did it because the container went over its memory limit.

Check how much it actually uses (needs metrics-server):

kubectl top pod checkout-7d9f8 -n shop --containers

If the limit is simply too low, raise it:

kubectl set resources deployment/checkout -n shop -c app \
  --requests=memory=768Mi --limits=memory=1Gi

Then put the same numbers in your manifests in git. Otherwise the next deploy quietly undoes your fix.

If memory keeps climbing until it dies, more memory only delays the next crash. That’s a leak, and the fix is in the code.

2. A traffic spike: more work than workers

The analogy: a restaurant at rush hour. You don’t make the chef cook faster. You bring in more cooks.

The symptom: latency climbs, CPU is pinned, maybe timeouts.

Right now, add replicas:

kubectl scale deployment/checkout -n shop --replicas=6

So you never have to do that by hand again, add a Horizontal Pod Autoscaler:

kubectl autoscale deployment checkout -n shop --min=2 --max=10 --cpu-percent=70

Two catches:

If CPU is the wrong signal, don’t write your own autoscaler. Scaling on queue length, Kafka lag or requests per second is what KEDA does, and it builds on the same autoscaler underneath.

3. A bad deploy: you need the undo button

The analogy: you’ve just pushed a change and things broke. Before debugging anything, go back to the version that worked. Investigate when the fire is out.

See the history:

kubectl rollout history deployment/checkout -n shop
REVISION  CHANGE-CAUSE
3         v1.4.1: cache fix
4         v1.5.0: new pricing

That CHANGE-CAUSE column is only useful if you fill it in. The old --record flag is deprecated, so annotate each deploy instead:

kubectl annotate deployment/checkout -n shop kubernetes.io/change-cause="v1.5.0: new pricing"

Roll back, and watch it finish:

kubectl rollout undo deployment/checkout -n shop --to-revision=3
kubectl rollout status deployment/checkout -n shop

Kubernetes keeps 10 old revisions by default. revisionHistoryLimit in the deployment changes that.

Better still: roll back through your CI/CD pipeline or GitOps tool. A rollback done only in the cluster leaves git pointing at the broken version, and the next deploy brings the bug straight back.

4. A silent failure: running, but wrong

The analogy: the patient is awake but not making sense. First listen. Then examine.

The symptom: the pod is Running with no restarts, but requests fail or return nonsense.

Listen: read the logs.

kubectl logs checkout-7d9f8 -n shop --since=15m
kubectl logs deployment/checkout -n shop --all-containers

If it did restart, the useful logs belong to the container that died:

kubectl logs checkout-7d9f8 -n shop --previous

Examine: get a shell inside.

kubectl exec -it checkout-7d9f8 -n shop -- sh

From there you can test DNS, call a dependency, or check a config file.

No shell in the image? Distroless and scratch images don’t have one. Bring your own toolbox instead, as an ephemeral debug container that shares the app’s processes:

kubectl debug -it checkout-7d9f8 -n shop --image=busybox:1.36 --target=app

It’s like a technician entering a locked server room with their own tools, without restarting anything.

5. CrashLoopBackOff: it dies as soon as it starts

The analogy: a car that stalls every time you turn the key. Kubernetes keeps turning it, waiting longer between tries: 10 seconds, 20, 40, up to five minutes.

The symptom:

NAME             READY   STATUS             RESTARTS
checkout-7d9f8   0/1     CrashLoopBackOff   7

Find out how it died:

kubectl describe pod checkout-7d9f8 -n shop     # Last State, Exit Code, Events
kubectl logs checkout-7d9f8 -n shop --previous   # its last words
kubectl events --for pod/checkout-7d9f8 -n shop  # what Kubernetes saw

The usual causes:

If the image can’t be pulled at all, you’ll see ErrImagePull or ImagePullBackOff instead. That’s a different problem: a wrong tag, a missing registry secret, or a typo.

When the logs say nothing, start a copy of the pod that runs a shell instead of the crashing command:

kubectl debug checkout-7d9f8 -n shop -it --copy-to=checkout-debug --container=app -- sh

Now you can run the real start command by hand and watch exactly where it fails. Delete checkout-debug when you’re done.

The cheat sheet

You see Run first Usual fix
OOMKilled, exit code 137 kubectl describe pod, kubectl top pod Raise the memory limit, or fix the leak
Slow under load kubectl top pod kubectl scale, then an autoscaler
Broke after a deploy kubectl rollout history kubectl rollout undo, then fix git
Running but wrong kubectl logs kubectl exec, or kubectl debug --target
CrashLoopBackOff kubectl logs --previous, kubectl describe pod Fix the command, config or probe

Most 3 a.m. pages are one of these five. Learn the first command for each, and you’ll spend less time guessing and more time fixing.