<p>Working on a project which is a k8s service which is implemented using flask.</p>
<p>As part of the deployment, I'd like to run db migrations before the app starts execution.</p>
<p>I was wondering what is considered &quot;best practice&quot;, and why.</p>
<p>Just mentioning here some of the ideas I had in mind:</p>
<ul>
<li>An <a href="https://stackoverflow.com/a/55223961">entrypoint.sh</a> script</li>
<li>An <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a></li>
<li>A <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/" rel="nofollow noreferrer">job</a></li>
<li>A <a href="https://stackoverflow.com/a/50506354">configmap</a></li>
</ul>
<p>if you had other approach/technique, be my guest :)</p>
<p>Thanks in advance!</p>

NI6
<p>The best practice would be to wrap all your app-related Kubernetes files in a helm chart, add the migration in a post-upgrade-hook which will ensure that is only run one time.</p>
<p>The problem with <code>entrypoint.sh</code> is that if you have more than 1 pod in your deployment, the migration will be run more than once...</p>
<p>More info on helm chart hooks:</p>
<p><a href="https://helm.sh/docs/topics/charts_hooks/" rel="nofollow noreferrer">https://helm.sh/docs/topics/charts_hooks/</a></p>
