<p>I use initContainers inside a deployment. An init container is created for each pods.</p>

<p>It is possible to get only one init container for the whole deployment ? </p>

<p>edit:</p>

<p>use case: need to run some db migration commands before creating the pods. So i have put these commands inside init pods.</p>

<p>problems:
- each time a pod is created, the init container is created
- on scale up init container is created</p>

<p>solution:
I have finally found a good example for solving this problem in <a href="https://gaunacode.com/deploying-onetime-jobs-to-kubernetes" rel="noreferrer">this article</a></p>

Georges Petrov
<p>While it is not possible to have one init container shared by whole deployment (which by definition is impossible as the unit of workload scheduling in kube is a pod), there are things you can use to get a similar functionality easily.</p>

<p>One way to achieve this would be to have an init container on every pod waiting for a specific job to be successfully executed, and a job that would do the actual init logic.</p>

<p>Another one would be to use leader election among your init containers so only one executes and the rest just wait for the lock to be release before they exit successfully.</p>
