Sub topic 18
A decision guide and prevention habits
This chapter assumes you know pods, deployments, and namespaces, and that you can read YAML and run kubectl get and kubectl describe. It ties together the earlier chapters into one decision path, then lists habits that stop many failures before they start.
Start from the status text
The STATUS column of kubectl get pod is your first branch point. It combines pod phase and container state, so each value points to a different family of causes.
Quick reference
| Symptom | Evidence to read | Usual cause | Fix |
|---|---|---|---|
| Pending, `Insufficient cpu` | `FailedScheduling` event, `describe node` | Requests exceed free capacity | Lower requests or add nodes |
| Pending, taint or selector message | `FailedScheduling` event | No node matches | Add a toleration or correct the selector |
| Pending, no scheduling event | `kubectl get pvc` | Claim is Pending | Fix the StorageClass or volume |
| ImagePullBackOff, `not found` | Pull event | Wrong image name or tag | Correct the reference |
| ImagePullBackOff, `unauthorized` | Pull event | Missing credentials | Add `imagePullSecrets` |
| CrashLoopBackOff, app error | `logs --previous` | Bad config or startup bug | Fix the app |
| CrashLoopBackOff, `OOMKilled` | `lastState.terminated` | Memory limit too low | Raise the limit |
| CrashLoopBackOff, exits on a schedule | Probe failure events | Liveness probe kills a slow app | Add a startup probe |
If logs and events do not explain the failure, attach a debug container with kubectl debug.
Prevention habits
These settings from the earlier chapters catch problems early. The manifest below combines them.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
imagePullSecrets:
- name: regcred
containers:
- name: app
image: registry.example.com/team/web:1.4.2
resources:
requests:
cpu: 250m
memory: 128Mi
limits:
memory: 256Mi
startupProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 5
failureThreshold: 30
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
failureThreshold: 3- Pin image tags to a specific version, as with
1.4.2, so a pull never depends on a tag that moved or vanished. - Set requests from measured usage so the scheduler places the pod on a node that can hold it.
- Set a memory limit with headroom above normal peaks, so a spike does not trigger
OOMKilled. - Use a startup probe for slow apps so the liveness probe does not restart them during startup.
- Create registry secrets in the same namespace as the pod.
Exercise
A pod shows CrashLoopBackOff. kubectl logs web --previous is empty, and lastState.terminated.reason is OOMKilled. What do you change, and why were the logs empty?
Show answer
Raise the memory limit, or reduce the app's memory use. The kernel killed the process abruptly when it exceeded the limit, so the app had no chance to write a final log line.
Exercise
A new pod stays Pending. Its describe output has no FailedScheduling event, but kubectl get pvc shows the claim as Pending. Which branch of the decision path applies?
Show answer
The unbound volume branch. Fix the claim, for example a missing or wrong StorageClass or no matching volume, and the pod can then be scheduled.