Using initcontainers in a job to do some stuff after pod initialization

9/5/2019

I'm currently trying to create a job in Kubernetes in a project I've just joined.

This job should wait until 2 other pods are up and running, then run a .sh script to create some data for the testers in the application.

I've figured out i should use initContainers. However, there is one point i don't understand.

Why should i include some environmental values under env tag under initContainers in job description .yaml file ?

I thought i was just waiting for the pods to be initialised, not creating them again. Am i missing something ?

Thanks in advance.

-- Emre Acar
kubernetes
kubernetes-jobs

1 Answer

9/5/2019

initContainers are like containers running in the Pod, but executed before the ones defined in the spec key containers.

Like containers, they share some namespaces and IPC, so it means that the Scheduler will check if the declared initContainers are successful, then it will schedule the containers.

Keep in mind that when you create a Pod, basically, you're creating an empty container named pause that will provide a namespace-base for the following containers: so, in the end, the initContainer is not really creating again a new Pod, like its name suggests, it's an initializer.

-- prometherion
Source: StackOverflow