key command for this task kubectl describe pods moc-turtle-b77d5466f-ztnb3 -n wonderland
A Pod can have multiple containers running apps within it, also it can have one or more init containers, which run before the app containers start.
We use init containers for running some stuff before main container starts.
Init containers are exactly like regular containers, except:
- Init containers always run to completion.
- Each init container must complete successfully before the next one starts.
Pod Template:
apiVersion: v1
kind: Pod
metadata:
name: <pod name>
...
spec:
initContainers:
- name: <init container name
image: <init container image>
<other parameters>
...
containers:
- name: <container name>
image: <container inage>
<other parameters>
...
<other parameters>
If a Pod’s init container fails, Kubernetes repeatedly restarts the
Pod until the init container succeeds. However, if the Pod has a restartPolicy
of Never
, Kubernetes does not restart the Pod.
Use Cases for Init Container:
- In Jenkins Pod, init container can preconfigure main Jenkins application (regular container): install plugins, configure settings, update. Once it’s done, regular container start with prepared configuration
- Init container can fetch encrypted secrets from a vault and write to file system
- Init Container can block app startup until another system is available (i.e., a queue or database server)
- Dynamic data fetched from a database and cached for the app to run after startup
Documentation:
- https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
- https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
Немає коментарів:
Дописати коментар