Init Containers
Init containers are used to run containers in the beginning of pod starting. These containers get finished and then actual containers get started. These containers can be used to run some initialization work, which requires to only once.
Init containers can be used by adding initContainers
section similar to containers
in pod definition yaml file.
initContainers:
- image: <image>
name: <name>
command:
- sh -c
- sleep 2000
Init containers are run to completion and app containers only start when init containers are finished. Init containers are run sequentially and if any init container fails, kubernetes restarts the pod and does this repeatedly until init containers complete.