Jenkins 03 |  master slave architecture

Jenkins 03 | master slave architecture

ยท

5 min read

Anything about jenkins exist in /var/lib/jenkins and download the code in workspace (path is /var/lib/jenkins/workspace )

Jenkins is the one who manage everything so we put jenkins in one single system from which it manage other slave nodes

here what jenkins will do is that any how jenkins detect change in code behind the scene it will launch the os and then download the code and build it and then delete this os. Automatically our cluster will keep on launching the slave node as and when required.

How to create a slave node and how to connect with the master node.

so here we are going to launch one node in which we setup Jenkins as a master node also we launch two slave nodes. In one slave node we install linux as operating system and other slave node contain windows as operating system.

whenever jenkins master send some instruction to slave node and say to slave that you have to perform it. when you are sending instruction from one system to another system we need some program in slave node which have a capability to take the information from the master and that program is called agent program.

so thats what we want to setup

But how jenkins connect to the linux system ?

since linux system support ssh so jenkins master connect to slave node using ssh and what things are required to ssh login is IP address, Username and password

click on jenkins dashboard >> manage jenkins >> nodes and clouds

write now we have only one node in which job is running and it is jenkins only

since we want to add more node so click on +node

here we are clicking on permanent Agent as we want the os even job build work get completed

here we connect the jenkins master to slave node using ssh username with private key not using password

since I have downloaded keypair of slave node so i will insert it directly as they don't provide the option to add private key file from aws directly

now click on add

then automatically new credential of ec2 user come in credential column

now there is one column which is mandatory to be filled

so lets create the folder in slave node where artifacts are saved

copy the path and paste it in remote root directory and since we have add the credentials of ec2-user then we have to make the directory in ec2 user not in root user otherwise errors will came

now we want to run 2 job parallely then we want two executors in slave node

then we have to add labels

then click on save let see what happen

In this we saw there is a issue from known host side not from jenkins as it trying to connect but fails due to ssh. As we all know when we first time connect using ssh then we have to say yes / no but in jenkin there is no way to say yes or no so what we can do .

for this we have to again configure it

so here we add the non verifying verification strategy mean don't ask me yes and no automatic feel yes from my side then save it and see what happen

so the step no 1 for connecting jenkins master to slave is done and step 2 agent program also done successfully

we have issue in third step run-registor

The issue is that jenkins is sending the agent and this program is written in language called Java so to run the agent program we want java (jdk )in slave node

better to use ansible it automate all the things about installing the java

here we are installing manually note that we have install that version that we have install in jenkins master. so lets install this in slave node in ec2-user

sudo amazon-linux-extras install java-openjdk11

or

sudo yum install java-11-openjdk

let again relaunch the agent

so this time agent is successfully connected and online. so all the steps are done

so step 1 for connectin jenkin master to slave node is done

step 2 for transferring the agent in slave node is done here the agent program name remoting.jar

step 3 running the agent is also done

so now we have one master node and one slave node

we create the job because I want to see whether the file is created in master or slave node

so in my case it is run on slave node so lets see

so if we want to run a particular job in which slave node then the role of labels came up that we have created earlier

so thats how we use master slave architecture

In Jenkins for running every jobs we required executor (build Executor) by default jenkins provide two executor mean we can run two independent jobs parallel at a time ( even we have hundreds of job running)

when you run three jobs simuntaneaously then two jobs run by the executor but third job will be in the build queue and after the completion of anyone of the job automatic the third job will be scheduled.

But if we have a requirement to run same job parallely then we have a option called execute concurrent builds if necessary under configure section of job.

see we can run the same job parrallely

but we want to increase the numbers of executors in jenkins

go jenkins dashboard>> manage jenkins >> System

we can increase the number of executor according to memory you have because some programs takes 5 mb of ram some require 1gb of ram and so on. So according we are taking 5 executor for testing purpose

so thats all guys we use master slave architecture and executors for running parallely

I hope you guys enjoys the blog do share and like it

want to connect with me ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

My Contact Info:

๐Ÿ“ฉEmail:-

LinkedIn:- linkedin.com/in/mayank-sharma-devops

ย