Kubernetes部署是否有继承的概念? [英] Is there a concept of inheritance for Kubernetes deployments?

查看:137
本文介绍了Kubernetes部署是否有继承的概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为Kubernetes部署创建继承树?我有许多类似但不完全相同的部署.它们共享许多ENV变量,但不是全部.它们都使用相同的图像.

Is there a way to create a tree of inheritance for Kubernetes deployments? I have a number of deployments which are similar but not identical. They share many ENV vars but not all. They all use the same image.

例如,我有一个dev部署,其配置与生产部署几乎相同,但是env vars指向不同的数据库后端.我有一个celery部署,其配置与生产部署相同,但是它具有不同的运行命令.

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.

推荐答案

头盔是许多人使用的这.它使您可以为kubernetes描述符创建模板,并传入参数以从模板生成描述符.

Helm is what many people are using for this. It let's you create templates for kubernetes descriptors and pass parameters in to generate descriptors from the templates.

还有其他工具可以通过将参数注入模板来在kubernetes部署描述符上生成变体. Ansible也很受欢迎.但是Helm与 Kubernetes CNCF紧密联系和社区,并且有很多官方图表可供选择.

There are other tools out there which can be used to generate variations on kubernetes deployment descriptors by injecting parameters into templates. Ansible is also popular. But Helm is closely connected with the Kubernetes CNCF and community and there's a good selection of official charts available.

如果目的是使用单个docker映像启用不同的部署(例如针对dev和prod),则最好使用单个图表进行处理.您可以为每个部署创建不同的值文件,并使用--values参数将所选的值文件提供给helm安装.如果图表中某些部分有时仅适用,则可以将它们包裹在if条件下以将其打开/关闭.

If the aim is to enable different deployments (e.g. for dev and prod) using a single docker image then that's probably best handled with a single chart. You can create different values files for each deployment and supply the chosen values file to helm install with the --values parameter. 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.

特别是在继承方面,有一个使用全局变量.如果您希望使用父级来减少重复而不是加入多个应用程序,则可以创建事实证明,仅复制配置会更好.

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. 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.

编辑(180119): Kustomize 的替代方法可能很快就会

EDIT (180119): The alternative of Kustomize may soon become available in kubectl

这篇关于Kubernetes部署是否有继承的概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆