best practice for flask migrations in kubernetes

3/31/2021

Working on a project which is a k8s service which is implemented using flask.

As part of the deployment, I'd like to run db migrations before the app starts execution.

I was wondering what is considered "best practice", and why.

Just mentioning here some of the ideas I had in mind:

if you had other approach/technique, be my guest :)

Thanks in advance!

-- NI6
database-migration
flask
kubernetes
python

1 Answer

3/31/2021

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.

The problem with entrypoint.sh is that if you have more than 1 pod in your deployment, the migration will be run more than once...

More info on helm chart hooks:

https://helm.sh/docs/topics/charts_hooks/

-- paltaa
Source: StackOverflow