I have database migrations which I\'d like to run before deploying a new version of my app into a Kubernetes cluster. I want these migrations to be run automatically as part of
Considering the age of this question I'm not sure if initContainers
were available at the time but they are super helpful now.
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
The way I recently set this up was to have a postgres
pod and our django
application running in the same namespace, however the django
pod has 3 initContainers
:
What this will do is run the django
pod and the postgres
pod in parallel but also continuously run the initContainers
until the postgres
pod comes up and then your migrations should run.
As for the pods perpetually restarting, maybe they've fixed the restartPolicy
by now. I'm currently pretty new to kubernetes but this is what I've found works for me.