<p>So i heard about <code>initConainers</code> which allow you to do pre-app-container initialization. However, i want initialization which are done either at the cluster level or statefulset, or even the whole pod.</p>

<p>For instance, I want to perform a one time hadoop namenode format on my persistent volumes and be done with that. After that is done my namenode statefulset and my datanode replicasets can proceed each time</p>

<p>Does <code>kubernetes</code> have anything to accommodate this?</p>

<p>How about its Extensions?</p>

Jeff Saremi
<p>Kubernetes itself provides <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="nofollow noreferrer">Jobs</a> for ad hoc executions. Jobs do not integrate very tightly with existing Pods/Deployments/Statefulsets. </p>

<p><a href="https://v3.helm.sh/" rel="nofollow noreferrer">Helm</a> is a deployment orchestrator and includes <a href="https://helm.sh/docs/charts_hooks/" rel="nofollow noreferrer"><code>pre</code> and <code>post</code> hooks</a> that can be used during an <code>install</code> or <code>upgrade</code>. </p>

<p>The <a href="https://helm.sh/docs/charts_hooks/#writing-a-hook" rel="nofollow noreferrer">helm docco provides a Job example</a> run <code>post-install</code> via annotations. </p>

<pre><code>metadata:
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": hook-succeeded
</code></pre>

<p>If you have more complex requirements you could do the same with a manager or Jobs that query the kubernetes API's to check on cluster state. </p>

<h3>Helm 3</h3>

<p>A warning that helm is moving to v3.x soon where they have rearchitected away a lot of significant problems from v2. If you are just getting started with helm, keep an eye out for the v3 beta. It's only alpha as of 08/2019.</p>
