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, or startupProbe.

3. Hands-On Lab: Day 03

In labs/k8s-30-days/day-03/:

  1. Create namespace ckad-day03.
  2. Deploy web-app with an initContainer (wait-for-db) that loops on nslookup mydb.ckad-day03.svc.cluster.local.
  3. Watch the Pod stay in Init:0/1 status until you create the mydb Service.
  4. Create mydb and run ./labs/k8s-30-days/day-03/verify.sh.

Search DivineForge