简体   繁体   English

Kubernetes 微服务版本控制

[英]Kubernetes Microservice Versioning

I'm fairly new to Kubernetes and only got started with an example project to learn everything.我对 Kubernetes 还很陌生,只是从一个示例项目开始学习一切。 I'm currently running one .NET microservice which needs a MongoDB as a database.我目前正在运行一个需要 MongoDB 作为数据库的 .NET 微服务。 The microservice is packed into a Docker Image and I've created a single Helm chart to properly deploy my microservice and the required MongoDB.微服务被打包到一个 Docker 镜像中,我创建了一个 Helm 图表来正确部署我的微服务和所需的 MongoDB。

Now I've thought about versioning and discovered one big problem with this approach: I can't just install multiple versions of that helm chart to support running multiple versions of the same microservice because that way each microservice gets its own database which is obviously not what I want.现在我考虑了版本控制并发现了这种方法的一个大问题:我不能只安装该 helm chart 的多个版本来支持运行同一微服务的多个版本,因为这样每个微服务都有自己的数据库,这显然不是我想要的是。

Does this mean I have to create two helm charts for my microservice?这是否意味着我必须为我的微服务创建两个舵图? So one api chart containing my .NET service and one db chart containing the MongoDB?那么一张包含我的 .NET 服务的api图表和一张包含 MongoDB 的db图表? That way I can deploy the MongoDB once and have multiple versions of my .NET service pointing to this single instance.这样我就可以部署 MongoDB 一次,并使我的 .NET 服务的多个版本指向这个单个实例。 However, that way I don't have a single Helm chart per microservice but multiple ones, which increases deployment overhead I'm guessing.但是,这样我每个微服务没有一个单一的 Helm 图表,而是多个,我猜这会增加部署开销。

Is this how it's been done?这是这样做的吗? Or is there something I'm missing?或者有什么我想念的吗? All clues that point me in the right direction are very welcome!非常欢迎所有为我指明正确方向的线索!

I would recommend one chart per service.我会为每项服务推荐一张图表。 The place where helm dependencies work well is where you have a service that embeds/hides specific single other parts. helm 依赖项运行良好的地方是您拥有嵌入/隐藏特定单个其他部分的服务。 And as @christopher said if your .NET service and MongoDB have different lifecycles, they shouldn't be packaged together in the same helm chart.正如@christopher 所说,如果您的 .NET 服务和 MongoDB 具有不同的生命周期,则不应将它们打包在同一个 helm chart 中。

The most basic way to use Helm is by having a single chart that holds a single application.使用 Helm 的最基本方法是拥有一个包含单个应用程序的图表。 The single chart will contain all the resources needed by your application such as deployments, services etc.单个图表将包含您的应用程序所需的所有资源,例如部署、服务等。

Chart versions and appVersions 图表版本和应用程序版本

The version of the chart itself (version field in Chart.yaml).图表本身的版本(Chart.yaml 中的版本字段)。 The version of the application contained in the chart (appVersion field in Chart.yaml).图表中包含的应用程序版本(Chart.yaml 中的 appVersion 字段)。 These are unrelated and can be bumped up in any manner that you see fit.这些是不相关的,可以以您认为合适的任何方式增加。 You can sync them together or have them increase independently.您可以将它们同步或让它们独立增加。 There is no right or wrong practice here as long as you stick into one.只要你坚持一种做法,这里就没有对错之分。

An important point here is that you need to adopt a policy in your team on what a “chart change” means.这里的重要一点是,您需要在您的团队中采用关于“图表更改”意味着什么的政策。

Helm does not enforce chart version changes. Helm 不会强制更改图表版本。 You can deploy a different chart with the same version as the previous one.您可以部署与前一个版本相同的不同图表。 So, if this is something that you want to do, you need to make sure that all teams are on the same page for versioning practices.因此,如果这是您想要做的事情,您需要确保所有团队都在同一页面上进行版本控制。

On the plus side, this workflow allows you to individually version charts and applications and is very flexible for companies with teams that manage separately the charts from the application source code.从好的方面来说,此工作流程允许您单独对图表和应用程序进行版本控制,并且对于拥有将图表与应用程序源代码分开管理的团队的公司来说非常灵活。

Umbrella charts 伞形图

However, you can also create a chart with dependencies to other charts called umbrella chart.但是,您也可以创建一个依赖于其他图表的图表,称为伞形图表。

They are completely external using the requirements.yaml file.它们是完全外部的,使用requirements.yaml文件。 Using this strategy is optional and can work well in several organizations.使用此策略是可选的,并且可以在多个组织中很好地工作。 Again, there is no definitive answer on right and wrong here, it depends on your team process.同样,这里没有对与错的明确答案,这取决于您的团队流程。

Take a look: umrella-charts-example .看一看: umrella-charts-example

In other words, a collection of software elements that each have their own individual charts but, for whatever reason (eg design choices, ease of deployability, versioning complexities), must be installed or upgraded as a since atomic unit换句话说,一组软件元素,每个元素都有自己的独立图表,但无论出于何种原因(例如设计选择、易于部署、版本控制复杂性),都必须作为自原子单元进行安装或升级

An umbrella chart references the version of the Helm chart itself and not the underlying version of the container image.伞形图引用 Helm 图表本身的版本,而不是容器映像的底层版本。 This means that any change to the image version will result in chart modifications to the individual component charts.这意味着对图像版本的任何更改都将导致对单个组件图表的图表修改。

What to take into account when deciding on an option决定选项时要考虑什么

There are two dimensions to take into account:有两个维度需要考虑:

  • Team structure : You have to ask yourself questions like: do you have small autonomous teams that are responsible for each service?团队结构:你必须问自己这样的问题:你有负责每项服务的小型自治团队吗? Do you have developers who have knowledge of DevOps?你有了解 DevOps 的开发人员吗?
  • Dependencies and reproducibility: You have to ask yourself questions like: How different are the dependencies for each service?依赖性和再现性:您必须问自己这样的问题:每个服务的依赖性有多大不同? What is the risk that a change to one service will break another?更改一项服务会破坏另一项服务的风险是什么? How do you reproduce the conditions of a specific development?您如何重现特定开发的条件?

Read more in useful article: helm-managing-microservices .在有用的文章中阅读更多内容: helm-managing-microservices

Speaking about versioning of microservices for backward compatibility, see Product Versioning Microservices , in general Semantic Versioning is generaly adviced.谈到微服务的版本控制以实现向后兼容性,请参阅产品版本控制微服务,通常建议使用语义版本控制

In the broader sense - there should be an agreed phase-out roadmap for major versions, that is communicated to API consumers (together with SLAs).在更广泛的意义上 - 应该有一个商定的主要版本的淘汰路线图,该路线图会传达给 API 消费者(与 SLA 一起)。 This is why tracking who uses your APIs is important.这就是跟踪谁使用您的 API 很重要的原因。 Take a look on this useful article about versioning management .看看这篇关于版本管理的有用文章

See example tool for tracking microservice versions- DeployHub .请参阅用于跟踪微服务版本的示例工具 - DeployHub

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

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