简体   繁体   English

Jenkins CD管道到Kubernetes

[英]Jenkins CD Pipeline to Kubernetes

I'm intending to have a CD Pipeline with Jenkins which takes my application, publishes a docker image to my private docker repository. 我打算与Jenkins一起使用CD Pipeline来获取我的应用程序,将docker镜像发布到我的私有docker存储库。 I think I know how to do that. 我想我知道该怎么做。

What I'm unsure about it the Kubernetes part. 我不确定Kubernetes的一部分。 I want to take that image and deploy it to my private Kubernetes cluster (currently 1 Master & 1 Slave). 我想拍摄该图像并将其部署到我的私人Kubernetes集群(目前是1个Master&1 Slave)。

Question: Does that Jenkins Slave which has kubectl and docker installed need to be part of the Kubernetes cluster in order to trigger a deployment? 问题:安装了kubectl和docker的Jenkins Slave是否需要成为Kubernetes集群的一部分才能触发部署? How can I trigger that deployment? 如何触发该部署?

Assuming that you have the following deployment in your cluster: 假设您在群集中进行了以下部署:

apiVersion: apps/v1beta1 # for versions before 1.6.0 use 
extensions/v1beta1
kind: Deployment
metadata:
   name: foobar-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: foobar-app
    spec:
      containers:
      - name: foobar
        image: foobar-image:v1
        ports:
        - containerPort: 80

You would have to somehow have Jenkins tell your Kubernetes master the following command: 你不得不以某种方式让Jenkins告诉你的Kubernetes掌握以下命令:

kubectl set image deployment/foobar-deployment foobar=foobar-image:version

where version is the new verion you just created with Jenkins. 其中version是您刚刚使用Jenkins创建的新version This will automatically trigger a redeploy with this version. 这将自动触发使用此版本的重新部署。

As long as you have access to your Kubernetes master that has your cluster on it (via ssh or similar), you can just pass the above command. 只要您可以访问具有群集的Kubernetes主服务器(通过ssh或类似服务器),您就可以通过上述命令。 Don't forget to keep track of version when you pass this command. 传递此命令时,请不要忘记跟踪version

You can trigger the deployment from Yenkin using kubectl command. 您可以使用kubectl命令从Yenkin触发部署。 for Quick start copy kubernetes cluster admin.conf or $HOME/.kube/config file to Jenkin slave server. 快速启动将kubernetes集群admin.conf或$ HOME / .kube / config文件复制到Jenkin从服务器。 Then you can run kubectl like this. 然后你可以像这样运行kubectl。

 Kubectl  --kubeconfig=admin.conf create –f <deployment.yml>

Note: 注意:

This will give full admin access to cluster, for long tream your can create account with deployment role and use that account for deployment. 这将为群集提供完全管理员访问权限,对于长tream,您可以创建具有部署角色的帐户并使用该帐户进行部署。

I'm intending to have a CD Pipeline with Jenkins which takes my application, publishes a docker image to my private docker repository. 我打算与Jenkins一起使用CD Pipeline来获取我的应用程序,将docker镜像发布到我的私有docker存储库。 I think I know how to do that. 我想我知道该怎么做。

That's right, this is the part we are all familiar with. 没错,这是我们都熟悉的部分。

My advice is that you actually, don't need to do much more in CI. 我的建议是,你实际上,不需要在CI中做更多的事情。

What I'm unsure about it the Kubernetes part. 我不确定Kubernetes的一部分。 I want to take that image and deploy it to my private Kubernetes cluster (currently 1 Master & 1 Slave). 我想拍摄该图像并将其部署到我的私人Kubernetes集群(目前是1个Master&1 Slave)。

It's hard to use CI reliably as a source of truth where you can track what's deployed where. 很难将CI可靠地用作事实来源,您可以在其中跟踪部署的位置。 What you can do instead is store app configuration (Deployment+Service YAML files) in a git repository and have git reconciliation operator that connects that repository to the cluster, you can even have multiple cluster setup this way. 您可以做的是将应用程序配置(部署+服务YAML文件)存储在git存储库中,并具有将该存储库连接到群集的git协调运算符,您甚至可以通过这种方式设置多个群集。

Question: Does that Jenkins Slave which has kubectl and docker installed need to be part of the Kubernetes cluster in order to trigger a deployment? 问题:安装了kubectl和docker的Jenkins Slave是否需要成为Kubernetes集群的一部分才能触发部署? How can I trigger that deployment? 如何触发该部署?

Some folks do run CI (such as Jenkins) in their Kubernetes clusters, and it is a legitimate approach, however, this means you have more things to run, and cut your self out from all the hosted CI options out there. 有些人在他们的Kubernetes集群中运行CI(例如Jenkins),这是一种合法的方法,但是,这意味着您可以运行更多的东西,并从那里的所有托管CI选项中削减自己。

The approach that we've been practising for a while now, is called GitOps and we blogged about various benefits of this approach: 我们现在已经练习了一段时间的方法称为GitOps,我们在博客中介绍了这种方法的各种好处:

See also: 也可以看看:


Disclaimer: I am a Kubernetes contributor and Weaveworks employee. 免责声明:我是Kubernetes贡献者和Weaveworks员工。 We build open-source and commercial tools that help people to get to production with Kubernetes sooner. 我们构建开源和商业工具,帮助人们更快地使用Kubernetes进行生产。

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

相关问题 Jenkins主站和从站安装在CI / CD管道上 - Jenkins master and Slave installation on CI/CD pipeline 如何使用Groovy和Kubernetes插件从Jenkins Pipeline运行Kafka? - How to run Kafka from Jenkins Pipeline using Groovy and Kubernetes plugin? 如何在kubernetes内运行的jenkins管道中运行sidecar容器 - How to run sidecar container in jenkins pipeline running inside kubernetes 如何使用 Helm 在 Kube.netes CI/CD 中使用 Azure Devops 发布管道变量? - How can I use Azure Devops Release Pipeline Variables in a Kubernetes CI/CD with Helm? 当用户单击应用程序中的按钮时,如何使用 GitLab CI 或 Jenkins 触发管道 CI/CD? - How can I trigger Pipeline CI/CD using GitLab CI or Jenkins when a user click on button in application? Jenkins和ECS的CI / CD - CI/CD with Jenkins and ECS Bitbucket jenkin kubernetes CI/CD - Bitbucket jenkin kubernetes CI/CD 如何仅针对 Jenkins 管道后期条件指定要在 Kubernetes 集群上执行的容器/代理 - How to specify a container / agent to execute on Kubernetes cluster for Jenkins pipeline post condition only 在 jenkins 管道中,在 azure kubernetes 服务的 Kubernetes pod 中执行 docker build 时,unix 上出现问题 Docker 守护进程套接字 - In jenkins pipeline getting issue Docker daemon socket at unix when doing docker build in Kubernetes pod of azure kubernetes services 詹金斯(Jenkins)和kubernetes在GKE上 - Jenkins with kubernetes on GKE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM