简体   繁体   English

使用 Kubernetes 初始化容器应用 EF 迁移

[英]Apply EF migration using the Kubernetes init containers

I want to migrate an Asp.Net Core app on Kubernetes.我想在 Kubernetes 上迁移 Asp.Net Core 应用程序。 Actually, inside the Program.cs class, there is the code that executes the migrations in the following way:实际上,在Program.cs class 中,有如下代码执行迁移:

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.我想从应用程序启动中删除它并创建一个 Docker 图像作为应用程序初始化容器的基础图像。

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.创建一个单独的控制台应用程序只是为了运行迁移,打包/发布为 docker 容器并在启动应用程序之前运行,也许使用运行状况检查等待再继续。 If you choose this options I would use the “worker” template because it already configures dependency injection.如果你选择这个选项,我会使用“worker”模板,因为它已经配置了依赖注入。

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.希望它有所帮助,它没有描述如何在您的应用程序之前运行任何一个选项,但我认为您可以在容器中使用kubernetes在其他容器之前运行任何容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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