An init container runs to completion before any main container starts. Init containers run one at a time, in order, and a failed one is retried, so each must be safe to run twice. They suit one-time preparation: waiting for a dependency, rendering configuration into a shared volume, running a migration. BookNest's API exits at startup if PostgreSQL 1,289 is unreachable, so its manifest starts with wait-for-db. Apply it before any database exists:
kubectl apply -f k8s/api-pod.yaml && sleep 8
kubectl get pod api && kubectl logs api -c wait-for-db | uniq -cOutput
pod/api created
NAME READY STATUS RESTARTS AGE
api 0/1 Init:0/1 0 8s
4 waiting for dbInit:0/1 means none of one init container has finished; the API container does not exist yet, so it cannot crash-loop. Init containers run only at Pod start, so a database that vanishes later is the readiness probe's job.