K8s by Example: Init Containers
| Init containers run before app containers start. They execute sequentially and must complete successfully. If any init container fails, the Pod restarts. Use for: migrations, config fetching, dependency checks. |
| pod-init.yaml | |
| Init containers are defined in | |
| pod-init-sequence.yaml | |
| Init containers run in order. Each must complete (exit 0) before the next starts. All init containers must succeed before app containers begin. | |
| pod-init-volume.yaml | |
| Init containers share volumes with app containers. Download files, generate config, clone repos, or prepare data. | |
| pod-wait-deps.yaml | |
| Wait for dependencies before starting the main app. Avoids race conditions during rollouts. Better than retry logic in your application code. | |
| pod-init-resources.yaml | |
| Init containers can have different resource limits than app containers. Useful when init needs more memory (migrations) but app needs less. Pod resource limits are the max of init and app containers. | |
| terminal | |
| Debug init containers when Pods stay in | |
| pod-init-timeout.yaml | |
| Init containers don’t support probes (liveness, readiness). They run to completion and exit. Use proper exit codes and timeouts in your init scripts to prevent hanging. | |