Sub topic 12
Debugging Pods Stuck in Init or with Failing Sidecars
This chapter assumes you can read Pod manifests, run kubectl get, describe and logs, and know how init containers run in order before app containers. It also assumes you know that a native sidecar is an init container with restartPolicy: Always.
Read the Pod status first
The STATUS column of kubectl get pod tells you where the Pod stopped. Start there.
| Status | Meaning |
|---|---|
| `Init:0/2` | No init container has finished yet. The Pod has 2 in total. |
| `Init:1/2` | The first init container finished. The second is running or waiting. |
| `Init:Error` | An init container exited with a non-zero code. |
| `Init:CrashLoopBackOff` | An init container keeps failing, and the kubelet is waiting longer between retries. |
| `Init:ImagePullBackOff` | The image of an init container cannot be pulled. |
| `PodInitializing` | All init containers are done. App containers are starting. |
For a native sidecar, the count includes it. A sidecar counts as started once it is running and its startup probe has passed, so a healthy sidecar does not hold the Pod at Init:N/M.
kubectl get pod web
kubectl describe pod web
kubectl logs web -c wait-for-dbA debugging workflow
Use the flow below as a checklist.
- Run
kubectl describe pod web. In theInit Containerssection, read each container'sState,Last State,Exit CodeandRestart Count. InEvents, look for pull failures, missing ConfigMaps or Secrets, and unbound volumes. - Run
kubectl logs web -c wait-for-db. You must name the container with-c, because the default container is not an init container. - If the container restarted, add
--previousto see the output of the last failed attempt. - If the container is running but never finishes, check what it waits for.
Common causes
The init container waits for something that never appears
The wait-for-db example loops until nslookup db.default.svc.cluster.local succeeds. The Pod stays at Init:0/1 and the logs repeat waiting for db. Typical reasons are a Service with a different name, a Service in another namespace, or a Service whose selector matches no Pods. Check with kubectl get svc db and kubectl get endpoints db.
The init container fails and retries
With the default restartPolicy: Always on the Pod, the kubelet restarts a failed init container with a growing back-off delay. With restartPolicy: Never, a failed init container fails the whole Pod. The app container never starts in either case.
A shared volume is empty or has the wrong path
In the web-with-content example, the init container writes to /work and nginx reads from /usr/share/nginx/html. Both mounts must name the same volume (content). If the paths or volume names differ, the Pod starts but serves the default page or a 403. Run kubectl exec web-with-content -c nginx -- ls /usr/share/nginx/html to check.
Resource requests block scheduling
An init container's request can make the Pod's effective request larger than any node can offer. The Pod then stays Pending, before any init container runs. kubectl describe pod shows a FailedScheduling event.
Failing sidecars
Sidecar failures look different because the Pod is often already serving traffic.
- Sidecar never becomes ready. The Pod stays in an Init state because the app container waits for the sidecar's startup probe. Check the probe path, port, and timing with
kubectl describe pod. - Sidecar crash-loops. The Pod shows
Init:CrashLoopBackOfforRunningwith a high restart count on the sidecar. Readkubectl logs app-with-log-sidecar -c log-shipper --previous. - Sidecar does not see the files. The sidecar and the app must mount the same volume, as
logsis mounted at/var/log/appin both containers in the example. - A Job never completes. A regular sidecar container keeps running after the main container exits, so the Job stays active. A native sidecar is stopped once the main containers finish, which lets the Job complete.
Exercise
Exercise
A Pod shows Init:1/2 for ten minutes. The first init container completed. What are your next two commands, and what do you look for in each?
Show answer
Run kubectl describe pod NAME and look at the second init container's State, Last State, Exit Code, and the Events. Then run kubectl logs NAME -c SECOND_INIT_CONTAINER (add --previous if it restarted) to read its output. The log usually shows the dependency or command that is failing.
Exercise
A Job with a regular sidecar container never reaches Completed, although the main container exited with code 0. Why, and what is a fix?
Show answer
The Pod keeps running because the sidecar never exits, so the Job sees an active Pod. Define the sidecar as a native sidecar (an init container with restartPolicy: Always), which Kubernetes stops after the main containers finish.