2

I want to know are the following scenarios possible , please help me out:-

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

Is this possible . I want to keep my local system as the Jenkins master .

Scenario 2:-

Can i spin up multiple containers as the Jenkins slave for local system as a Jenkins master.

Thanks

aditya rawat
  • 129
  • 2
  • 18

2 Answers2

3

Scenario 1 is at least covered by the JENKINS/Kubernetes Plugin: see its README

Based on the Scaling Docker with Kubernetes article, automates the scaling of Jenkins agents running in Kubernetes.

But that requires a Kubernetes setup, which means, in your case (if you have only one machine), a minikube.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi , I am not able to get the flow of the whole procedure , Is it like first setup the Jenkins on my system, then create k8s pods as slave , and then run the jenkins project . – aditya rawat Feb 08 '18 at 11:06
  • 1
    You don't create pods as slave: each job will dynamically create its own temporary pods for its execution. – VonC Feb 08 '18 at 11:23
1

I have written a message on Scenario 1 (with Kubernetes) at this link:

Jenkins kubernetes plugin not working

Here the post.

Instead of using certificates, I suggest you to use credentials in kubernetes, by creating a serviceAccount:

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

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):

enter image description here

enter image description here

For credentials:

enter image description here

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:

enter image description here

My instructions are for the Jenkins master inside kubernetes. 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.

Nicola Ben
  • 10,615
  • 8
  • 41
  • 65