简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM