Build · shipped
30 Days of Kubernetes (CKAD) — Day 03: Init Containers & Startup Dependencies
Day 03 of the 30-day CKAD hands-on series: sequencing startup dependencies and database checks with Init Containers.
Unlike sidecars (which run alongside your app), Init Containers run before your main application containers start. Each Init Container must exit with status 0 before the next one runs.
1. Why Use Init Containers?
- Wait for dependencies: Block until a database or upstream Service is resolvable via DNS.
- Security isolation: Fetch secrets or run DB migrations using tools (
curl,psql,git) that you don't want inside your lean production container image.
2. Key Exam Behaviors
- Init containers run sequentially, one at a time.
- If an Init Container fails, Kubernetes restarts the Pod until it succeeds (unless
restartPolicy: Never). - Init Containers do not support
readinessProbe,livenessProbe, orstartupProbe.
3. Hands-On Lab: Day 03
In labs/k8s-30-days/day-03/:
- Create namespace
ckad-day03. - Deploy
web-appwith aninitContainer(wait-for-db) that loops onnslookup mydb.ckad-day03.svc.cluster.local. - Watch the Pod stay in
Init:0/1status until you create themydbService. - Create
mydband run./labs/k8s-30-days/day-03/verify.sh.