Salvatore Calla'
Salvatore Calla'

Reputation: 153

Apply EF migration using the Kubernetes init containers

I want to migrate an Asp.Net Core app on Kubernetes. Actually, inside the Program.cs class, there is the code that executes the migrations in the following way:

context.Database.Migrate();

I would like to remove this from the application startup and create a Docker image to use as the base image for the application init container.

Any suggestion?

Upvotes: 0

Views: 1683

Answers (1)

Stephan
Stephan

Reputation: 2590

You have at least two options to run the migrations separately from the application.

  1. Change the app startup a little bit to look for a specific startup argument, then run the migrations and exit afterwards. This options helps you to keep it simple (no duplicate startup, no second container, everything in the same app)
  2. Create a separate console app just to run the migrations, package/publish as docker container and run before starting the app, maybe use the health check to wait before continuing. If you choose this options I would use the “worker” template because it already configures dependency injection.

Hope it helps, it doesn’t describe how to run either option before your app but I think you can use the kubernetes into container to run any container before the others.

Upvotes: 1

Related Questions