0

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
  • 2,477
  • 5
  • 17
  • 28
  • Out of your list, only "job" will run a single time. The rest will run as times as your have replicas and it will happen on every pod restart. – jordanm Mar 31 '21 at 15:53

1 Answers1

3

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
  • 2,985
  • 13
  • 28