Kubernetes Init Containers: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
m (Ovidiu moved page Kuberentes Init Containers to Kubernetes Init Containers without leaving a redirect)
Line 23: Line 23:


Init containers can be used to run utilities that do not belong in application [[Kubernetes_Pod_and_Container_Concepts#Application_Containers|application container]] images for security reasons. They can also contain utilities for setup or dependency wait loops: they run to completion before any application containers start, whereas application containers run in parallel, so init containers provide an easy way to block or delay the startup of application containers until some set of preconditions are met. The application image builder and deployer roles can work independently without the need to jointly build a single application image. Because they use Linux namespaces so that they have different filesystem views from application containers, they can be given access to Secrets that application containers should not be able to access.
Init containers can be used to run utilities that do not belong in application [[Kubernetes_Pod_and_Container_Concepts#Application_Containers|application container]] images for security reasons. They can also contain utilities for setup or dependency wait loops: they run to completion before any application containers start, whereas application containers run in parallel, so init containers provide an easy way to block or delay the startup of application containers until some set of preconditions are met. The application image builder and deployer roles can work independently without the need to jointly build a single application image. Because they use Linux namespaces so that they have different filesystem views from application containers, they can be given access to Secrets that application containers should not be able to access.
=Lifecycle=
<font color=darkgray>TODO: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#detailed-behavior</font>
==Timeout==
An init container must finish initializing within <font color=darkgray>TODO: how much?</font> otherwise it puts the deployment into an error state:
NAME        READY    STATUS    RESTARTS  AGE
a-1-deploy  0/1      Error    0          13m

Revision as of 01:51, 19 September 2019

External

Internal

Overview

An init container is a specialized container that runs before the application containers, and can contain utilities or setup scripts not present in the application image. If a pod declares init containers, the application containers are only run after all init container complete successfully.

An init container always runs to completion, and if more than one init containers are declared, each one is executed sequentially and must complete successfully before the next one is started. This is the reason init containers do not support readiness probes: they must succeed. If an init container fails, Kubernetes will restart the Pod repeatedly until the init container succeeds, unless the pod has a "restartPolicy" of "Never".

While an init container is executed, it shows as "Init:*/*", alongside the deployment container.

kubectl get pods
NAME         READY     STATUS     RESTARTS   AGE
a-1-7k94g    0/1       Init:0/1   0          3m
a-1-deploy   1/1       Running    0          3m

Init containers support all the fields and the features of the application containers including resource limits, volumes and security settings. However, the resource requests and limits for an init container are handled slightly differently, as described in Resources below.

Init containers can be used to run utilities that do not belong in application application container images for security reasons. They can also contain utilities for setup or dependency wait loops: they run to completion before any application containers start, whereas application containers run in parallel, so init containers provide an easy way to block or delay the startup of application containers until some set of preconditions are met. The application image builder and deployer roles can work independently without the need to jointly build a single application image. Because they use Linux namespaces so that they have different filesystem views from application containers, they can be given access to Secrets that application containers should not be able to access.

Lifecycle

TODO: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#detailed-behavior

Timeout

An init container must finish initializing within TODO: how much? otherwise it puts the deployment into an error state:

NAME         READY     STATUS    RESTARTS   AGE
a-1-deploy   0/1       Error     0          13m