简体   繁体   English

Docker容器作为Jenkins从站

[英]Docker Containers as Jenkins Slave

I want to know are the following scenarios possible , please help me out:- 我想知道以下几种可能的情况,请帮帮我:-

Scenario 1 :- 情况1 :-

I have my local system as a Jenkins Master and Every time I need A slave to run my automation test script , a docker container spins up as a Jenkins slave and my script is executed on the slave and after the execution is completed the container is destroyed . 我将本地系统作为Jenkins主服务器,每次需要一个从属服务器来运行自动化测试脚本时,都会将一个Docker容器旋转为Jenkins从属服务器,并且我的脚本在该从属服务器上执行,执行完成后,该容器将被销毁。

Is this possible . 这可能吗 。 I want to keep my local system as the Jenkins master . 我想保留我的本地系统作为Jenkins管理员。

Scenario 2 :- 方案2 :-

Can i spin up multiple containers as the Jenkins slave for local system as a Jenkins master. 我可以作为Jenkins主服务器启动多个容器作为本地系统的Jenkins从服务器。

Thanks 谢谢

Scenario 1 is at least covered by the JENKINS/Kubernetes Plugin : see its README JENKINS / Kubernetes插件至少涵盖了方案1:请参阅其自述文件

Based on the Scaling Docker with Kubernetes article , automates the scaling of Jenkins agents running in Kubernetes. 根据使用Kubernetes扩展Docker的文章 ,自动运行在Kubernetes中运行的Jenkins代理的扩展。

But that requires a Kubernetes setup, which means, in your case (if you have only one machine), a minikube . 但这需要Kubernetes设置,这意味着,在您的情况下(如果只有一台机器)是minikube

I have written a message on Scenario 1 (with Kubernetes) at this link: 我通过以下链接在方案1(使用Kubernetes)上写了一条消息:

Jenkins kubernetes plugin not working Jenkins kubernetes插件不起作用

Here the post. 这里的帖子。

Instead of using certificates, I suggest you to use credentials in kubernetes, by creating a serviceAccount: 建议您不要创建证书,而是通过创建serviceAccount在kubernetes中使用凭据:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: jenkins
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["pods/exec"]
  verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
  resources: ["pods/log"]
  verbs: ["get","list","watch"]
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: jenkins
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: jenkins
subjects:
- kind: ServiceAccount
  name: jenkins

and deploying jenkins using that serviceAccount: 并使用该serviceAccount部署jenkins:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: jenkins
  name: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:           
      serviceAccountName: jenkins 
....

I show you my screenshots for Kubernetes plugin (note Jenkins tunnel for the JNLP port, 'jenkins' is the name of my kubernetes service): 我为您显示了Kubernetes插件的屏幕截图(请注意JNLP端口的Jenkins隧道,“ jenkins”是我的kubernetes服务的名称):

在此处输入图片说明

在此处输入图片说明

For credentials: 对于凭据:

在此处输入图片说明

Then fill the fileds (ID will be autogenerated, description will be shown in credentials listbox), but be sure to have created serviceAccount in kubernetes as I said before: 然后填写文件(ID将自动生成,描述将显示在凭据列表框中),但是请确保像我之前说的那样在kubernetes中创建了serviceAccount:

在此处输入图片说明

My instructions are for the Jenkins master inside kubernetes. 我的说明适用于kubernetes中的Jenkins大师。 If you want it outside the cluster (but slaves inside) I think you have to use simple login/password credentials. 如果您想在集群外部(但在从服务器内部),则必须使用简单的登录/密码凭证。

I hope it helps you. 希望对您有帮助。

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

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