简体   繁体   English

是否存在Kubernetes部署的继承概念?

[英]Is there a concept of inheritance for Kubernetes deployments?

Is there a way to create a tree of inheritance for Kubernetes deployments? 有没有办法为Kubernetes部署创建继承树? I have a number of deployments which are similar but not identical. 我有许多类似但不完全相同的部署。 They share many ENV vars but not all. 他们共享许多ENV变量而不是全部。 They all use the same image. 他们都使用相同的图像。

For example, I have a dev deployment which is configured almost identical to a production deployment but has env vars pointing to a different database backend. 例如,我有一个开发部署,其配置几乎与生产部署相同,但具有指向不同数据库后端的环境变量。 I have a celery deployment which is configured the same as the production deployment, however, it has a different run command. 我有一个芹菜部署,其配置与生产部署相同,但是,它具有不同的运行命令。

Helm is what many people are using for this. Helm是许多人正在使用的。 It let's you create templates for kubernetes descriptors and pass parameters in to generate descriptors from the templates. 它允许您为kubernetes描述符创建模板并传递参数以从模板生成描述符。

There are other tools out there which can be used to generate variations on kubernetes deployment descriptors by injecting parameters into templates. 还有其他工具可用于通过将参数注入模板来生成kubernetes部署描述符的变体。 Ansible is also popular. Ansible也很受欢迎。 But Helm is closely connected with the Kubernetes CNCF and community and there's a good selection of official charts available. 但Helm与Kubernetes CNCF和社区紧密相连,并且有很多官方图表可供选择。

EDIT: If the aim is to enable different deployments (eg for dev and prod) using a single docker image then that's probably best handled with a single chart. 编辑:如果目标是使用单个泊坞窗图像启用不同的部署(例如dev和prod),那么最好用单个图表处理。 You can create different values files for each deployment and supply the chosen values file to helm install with the --values parameter. 您可以为每个部署创建不同的值文件,并使用--values参数将所选值文件提供给helm install。 If there are parts of the chart that are only sometimes applicable then they can be wrapped in if conditions to turn them on/off. 如果存在仅适用有时则它们可以被包裹在该图表的零件if条件,从而开启/关闭。

On the subject of inheritance specifically, there's an example in the helm documention of how to take another chart as a parent/dependency and override its values and I created a chart earlier that you can see in github that includes several other charts and overrides parts of all of them via the values.yml . 关于继承的主题, 在helm文档中有一个例子,如何将另一个图表作为父/依赖关系并覆盖其值 ,我之前创建了一个图表,您可以在github中看到包含其他几个图表覆盖部分 图表 。所有这些都通过values.yml It also shares some config between the included charts with globals . 它还在包含全局变量的图表之间共享一些配置。 If you're looking to use a parent to reduce duplication rather than join multiple apps then it is possible to create a base/wrapper chart but it may turn out to be better to just duplicate config . 如果您希望使用父级来减少重复而不是加入多个应用程序,则可以创建基本/包装图表,最好只重复配置

EDIT (180119): The alternative of Kustomize may soon become available in kubectl 编辑(180119):的替代Kustomize可能很快成为kubectl可用

You may also want to check Kustomize . 您可能还想检查Kustomize It provides some support to write your yaml manifests in hierarchical form, so that you don't have to repeat yourself. 它提供了一些支持,以分层形式编写您的yaml清单,这样您就不必重复自己。

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

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