Definition:

  • specialized containers that run successfully before app containers in a Kubernetes Pod
  • Init containers can contain utilities or setup scripts not present in an app image.
  • Use cases:
    1. Database readiness: Verify connection or schema migration before app startup.
    2. External API health checks: Ensure critical APIs are reachable.
    3. File or directory initialization: Create required directories or files for the app.
    4. Fetching secrets/configurations: Download secrets from external systems.
    5. Cleaning up temporary files: Ensure temporary files from previous runs are removed.

Understand init containers

  • Run before the main app containers are started (sequentially)
  • Init containers:
    • always run to completion
    • each init container must complete successfully before the next one starts
  • If a Pod’s init container fails, kubelet daemon repeatedly restarts until it succeed (without restartPolicy: Always, if set it become Kubernetes Sidecar Container)
    • can set restartPolicy to Never
Differences from regular Container
Differences from Kubernetes Sidecar Container
  • initContainers do not run continuously
  • donot support lifecyclelivenessProbereadinessProbe, or startupProbe

Using init containers

Detailed behavior