Init Containers

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:

The API Pod held at its init container while the database is missingShell
kubectl apply -f k8s/api-pod.yaml && sleep 8
kubectl get pod api && kubectl logs api -c wait-for-db | uniq -c
Output
pod/api created
NAME   READY   STATUS     RESTARTS   AGE
api    0/1     Init:0/1   0          8s
      4 waiting for db

Init: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.