简体   繁体   English

在Kubernetes上自动化部署

[英]Automate deployments on Kubernetes

I am interested in know what is the best way to automate YAML deployments in Kubernetes 我有兴趣知道在Kubernetes中自动化YAML部署的最佳方法是什么

I have a cert-manager helm installation and a kong YAML manifest and an Ingress resource created, installed and working in a Kubernetes cluster 我安装了cert-manager头盔和kong YAML清单,并在Kubernetes集群中创建,安装并使用了Ingress资源

This deployment provides me TLS encryption in order to get the https protocol to my application service which also is installed via helm (I've created a helm chart for it) 此部署为我提供了TLS加密,以便将https协议获取到我的应用程序服务,该协议也通过helm安装(我已经为其创建了helm图表)

My objective is to find the way of executing those YAML files that I have created, and some helm commands of an automatic way and not execute manually the steps and the process. 我的目标是找到执行我创建的YAML文件的方式以及一些自动执行的helm命令,而不是手动执行步骤和过程。

Maybe is important to keep in mind that all these cert-manager, kong and Ingress deployment is associated to my helm chart service application which I've created, so that I have been deploying the following: 请记住,所有这些证书管理器,kong和Ingress部署都与我创建的Helm Chart Service应用程序相关联,也许很重要,因此我一直在部署以下内容:

  1. I've created a helm chart of my service application and I've installed it via helm install ... command 我已经创建了服务应用程序的Helm图表,并通过helm install ...命令安装了它

  2. I've installed kong and kong-ingress-controller from a YAML manifest using Postgres like external service. 我已经使用外部服务之类的Postgres从YAML清单中安装了kongkong-ingress-controller

  3. I've installed cert-manager via helm adding its helm repo add jetstack https://charts.jetstack.io and executing 我已经通过头盔安装了cert-manager ,添加了helm repo add jetstack https://charts.jetstack.io并执行

helm install \
    --name cert-manager \
    --namespace cert-manager \
    --version v0.7.0 \
    jetstack/cert-manager
  1. And also, I have created an Ingress and KongIngress resources to allow the access to my helm chart application service and allow to kong manage the ingress operations and other actions like the routes, certificates and service creation, and also associate somethings like basic-auth plugin to my service application 而且,我还创建了一个IngressKongIngress资源,以允许访问我的头盔图表应用程序服务,并允许kong管理入口操作和其他操作,例如路由,证书和服务创建,还关联诸如basic-auth插件之类的东西我的服务申请

All this process was made via kubectl apply ... executing YAML files and also helm .... command from a CLI. 所有这些过程都是通过kubectl apply ...执行YAML文件以及来自CLI的helm ....命令完成的。

This mean, that currently this process is highly dependent of an human events, and I would like to automatize somethings like the kong and cert-manager installation process and even if is possible the Ingress creation. 这就是说,当前该过程高度依赖于人为事件,因此我想自动化诸如kongcert-manager安装过程之类的程序,即使可能创建Ingress

Do I am right when I think that this may be possible? 当我认为这可能实现时,我是否正确?

What is the best way to do it? 最好的方法是什么?

I have been reading and looking in some places, and some people also have orient me in the following alternatives: 我一直在一些地方阅读和查找,有些人也将我定向到以下替代方法中:

  • From my helm chart application ? 从我的掌舵图表应用程序中?

    I have been reading that helm has something named hooks 我一直在读头盔有一个叫做hooks东西

The hooks itself describe the following: hooks本身描述以下内容:

A kind of mechanism to allow chart developers to intervene at certain points in a release's life cycle. 一种机制,允许图表开发人员在发布的生命周期中的某些时间进行干预。 For example, you can use hooks to: 例如,您可以使用挂钩来:

Load a ConfigMap or Secret during install before any other charts are loaded. 在加载任何其他图表之前,请在安装期间加载ConfigMap或Secret。

Execute a Job to back up a database before installing a new chart, and then execute a second job after the upgrade in order to restore data. 在安装新图表之前,请执行作业以备份数据库,然后在升级后执行第二个作业以还原数据。

Run a Job before deleting a release to gracefully take a service out of rotation before removing it 在删除发行版之前运行作业,以便在删除发行版之前适当取消服务

Could be the helm hooks approach a good option? 头盔挂钩可能是一个不错的选择吗? I think that with them I can automatize or at least that the helm chart application take over the secrets creation and some pre/post-deployment . 我认为,有了它们,我就可以实现自动化,或者至少可以由helm chart应用程序来接管秘密创建和一些pre/post-deployment

Can I consider the kong , cert-manager and Ingress resources operations (commands and YAML files execution) like operations or actions to be managed by helm hooks? 我是否可以将kongcert-managerIngress资源操作(命令和YAML文件执行)之类的操作或动作视为由头盔挂钩进行管理?

  • Terraform approach: Providing the deployment (some steps or completely) from it. Terraform方法:从中提供部署(某些步骤或完全)。

There is a Helm and Kubernetes providers available from terraform. terraform有Helm和Kubernetes提供商。 I could explore that possibility of install these software packages from terraform scripts. 我可以探索从terraform脚本安装这些软件包的可能性。

This terraform approach could be useful to install my helm chart application and the cert-manager helm 这种terraform方法可能对安装my helm chart applicationcert-manager头盔很有用

Kong also like terraform provider Kong也喜欢terraform提供商

Currently there are some third party repositories to work with kong from terraform. 当前,有一些第三方存储库可与Terraform中的kong合作。 Terraform Provider Kong it's more proper to me due to I am using Azure Kubernetes service, and the different resource configurations which are possible to implement looks very good. Terraform Provider Kong对我来说更合适,因为我使用的是Azure Kubernetes服务,并且可以实现的不同资源配置看起来非常好。 I am not sure if I would have to inject manually somethings like certificates , route resources when I work with the kong-ingress-controller and cert-manager communication, but even this terraform kong provider allow me the possibility of import a existing routes terraform import kong_route.<route_identifier> <route_id> 我不确定在与kong-ingress-controller和cert-manager通讯时是否必须手动注入certificatesroute资源之类的东西,但是即使是这个terraform kong提供商也允许我导入现有的路径terraform import kong_route.<route_identifier> <route_id>

Could be apply it this to certificates and other resources? 可以将其应用于certificates和其他资源吗?

  • Using python scripts 使用python脚本

What about of automate deployments via python? 通过python自动部署怎么样? How are going the things with this alternative? 这种选择的情况如何? Is possible do it interacting from python to kubernetes and executing the commands operations which I have described above ( kubectl and helm to create resources from YAML files and helm charts available in local and remote repositories) 是否有可能从python到kubernetes交互并执行我上面描述的命令操作( kubectlhelm从本地和远程存储库中的YAML文件和helm图表创建资源)

In affirmative case ... How to can I address this option? 如果是肯定的话...我该如何解决这个问题?

I have found this option which use ansible but it involve some other things like Automate broker ansible and Kubernetes service catalog, which are unknown for me at the moment. 我发现这个使用ansible的选项,但是它涉及其他一些事情,例如automate broker ansible和Kubernetes服务目录,这对我来说目前还不知道。

  • Using Jupyter Notebooks. 使用Jupyter笔记本。

Can I create those resources ( Ingress and kong and cert-manager installation and configuration) via jupyter notebooks, writing down directly to Kubernetes cluster? 我可以通过jupyter笔记本创建这些资源( Ingress和kong以及cert-manager安装和配置),直接写到Kubernetes集群吗? Is this possible? 这可能吗? How to can I do it? 我该怎么办?

So, I think that the terraform approach (using the helm and kong providers would be very useful tools from a infrastructure as a code perspective, but I am not sure if I would be choose it, maybe could there is less complex alternatives? 因此,我认为terraform方法(从代码基础结构的角度来看,使用helmkong提供商将是非常有用的工具,但是我不确定是否会选择它,也许有没有那么简单的替代方法?

Somebody has performed automation of resources and things in Kubernetes cluster. 有人在Kubernetes集群中执行了资源和事物的自动化。 I suppose that it is a normal or expected process to do, although is my first time. 我想这是一个正常或预期的过程,尽管这是我第一次。

If someone can point me in the right approach to solve my particular scenario I will be highly grateful. 如果有人可以指出正确的方法来解决我的特定情况,我将不胜感激。 :) :)

Unfortunately you cannot control the order of installation of dependent Helm charts. 不幸的是,您无法控制相关Helm图表的安装顺序。 Helm groups together the chart's templates and all of its dependencies' templates and applies them as if they came from the same chart (see here for more details on the ordering). Helm将统计图的模板及其所有依赖项的模板分组在一起,并像应用来自同一统计图一样对其进行应用(有关订购的更多详细信息,请参见此处 )。

You could write a Python script that installs the charts one after the other using PyHelm (full disclosure - I'm one of the maintainers of the package). 您可以编写一个Python脚本,使用PyHelm依次安装图表(全面披露-我是软件包的维护者之一)。

In addition, you can use Helm hooks in order to control the order of the installation - that can take care of your additional yamls (eg using the post-install/post-upgrade hooks). 另外,您可以使用Helm挂钩来控制安装的顺序-可以照顾您的其他Yaml(例如,使用安装后/升级后的挂钩)。

A possible solution is to use initContainer that will wait for other services to be UP. 一种可能的解决方案是使用initContainer,它将等待其他服务启动。

Typically, for a given A and B application, you will use helm or event better helmfile to deploy them both at the same time. 通常,对于给定的A和B应用程序,您将使用helm或事件更好的helmfile来同时部署它们。 But for the pod of B, you will add an initContainer, that will check say every 10 seconds if service A is started. 但是对于B的Pod,您将添加一个initContainer,如果启动服务A,它将每10秒检查一次。 By doing this, you are sure that service B will only start when service A is fully started and ready. 这样,您可以确保仅在服务A完全启动并准备就绪时启动服务B。 You can have a look at https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ . 您可以查看https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ This requires to configure livenessProbe and readynessProbe. 这需要配置livenessProbe和readynessProbe。

Note that this will not really order chart installation, simply ensure that each service will wait for dependendancies before start. 请注意,这实际上并不会定购图表,只需确保每个服务在启动之前都将等待依赖关系。 And you can install many chart at the same time using helmfile ( https://github.com/roboll/helmfile ). 您可以使用helmfile( https://github.com/roboll/helmfile )同时安装许多图表。

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

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