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:
- Database readiness: Verify connection or schema migration before app startup.
- External API health checks: Ensure critical APIs are reachable.
- File or directory initialization: Create required directories or files for the app.
- Fetching secrets/configurations: Download secrets from external systems.
- 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
- initContainers do not run continuously
- donot support
lifecycle, livenessProbe, readinessProbe, or startupProbe
Using init containers
Detailed behavior