TL;DR: you can leverage the
pre-install
andpre-upgrade
Helm hooks to run database migrations before your application is installed or updated. Keep reading to understand why simpler solutions might not be good ideas and a couple of gotchas when using Helm hooks.
If your application uses a relational database, your schema will evolve over time. Before deploying a new version of you application, you will have to ensure that the database schema is up to date. This article is not about how to generate and manage schema migrations (there are multiple tools to handle that) but how to apply them as part of the application deployment process on Kubernetes.
You could decide to run migrations automatically as part of your service startup. This might seem like a good idea: it guarantees that your service will not start before the migrations are applied and removes the risk of running an application on an outdated schema.
But when running on Kubernetes, this poses a couple of issues:
#kubernetes #helm #devops #database