Init container chạy xong trước app containers. Nó phù hợp chuẩn bị file/config, chờ dependency nội bộ, chạy migration nhẹ có kiểm soát hoặc setup permission cho volume.
Ví dụ:
yaml
initContainers:
- name: wait-db
image: busybox:1.36
command: ["sh", "-c", "until nc -z db 5432; do sleep 2; done"]Không nên dùng init container để che lỗi kiến trúc như app không retry được dependency.
App production vẫn nên tự retry/backoff hợp lý.
An init container runs to completion before app containers. It fits preparing files/config, waiting for internal dependencies, running controlled lightweight migrations or setting up volume permissions.
Example:
yaml
initContainers:
- name: wait-db
image: busybox:1.36
command: ["sh", "-c", "until nc -z db 5432; do sleep 2; done"]Do not use init containers to hide architecture issues such as an app that cannot retry dependencies.
Production apps should still have sensible retry/backoff.