Guide to Understanding Jenkins🧛♂️Master-Slave 👷♂️👷♀️ Architecture 🚀
Day 28 Task: 90DaysOfDevOps Challenge
Jenkins, the open-source automation server, is a powerhouse tool for continuous integration and continuous delivery (CI/CD). One of its standout features is the master-slave architecture, which empowers users to scale their build and deployment processes efficiently. 🏗️
🎆 Introduction
In this blog post, we'll deep dive into the Jenkins master-slave architecture
, exploring its benefits, setting it up, and providing an example to illustrate its usage. 🌐
🧛♂️ Jenkins Master
Jenkins’s server or master node holds all key configurations. The Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines.
👇 Following are the characteristics of Jenkins Master:
Scheduling build jobs.
Dispatching builds to the slaves for the actual execution.
Monitor the slaves (possibly taking them online and offline as required).
Recording and presenting the build results.
A Master instance of Jenkins can also execute build jobs directly.
👷♂️👷♀️ Jenkins Slave/Workers
An agent is typically a Java executable that runs on a machine or container that connects to a Jenkins master and this agent actually executes all the steps mentioned in a Job.
When you create a Jenkins job, you have to assign an agent to it. Every agent has a label as a unique identifier.
When you trigger a Jenkins job from the master, the actual execution happens on the agent node that is configured in the job.
👇 Following are the characteristics of Jenkins Master:
It hears requests from the Jenkins Master.
Slaves can run on a variety of operating systems.
You can configure a project to always run on a particular Slave machine or a particular type of Slave machine.
🌟Benefits of Jenkins Master-Slave Architecture
🔹 Scalability: Master-slave architecture enables distributing workloads across multiple nodes, improving performance and accommodating larger projects.
🔹 Resource Optimization: Slaves can be configured on different machines with different operating systems and hardware, optimizing resource utilization.
🔹 Isolation: Build jobs on different slaves run in isolated environments, preventing dependencies or conflicts from affecting each other.
🔹 24/7 Availability: With dedicated slave nodes, builds and deployments can continue even if the master node experiences downtime.
🔹 Security: Sensitive code and data can be isolated on specific slave nodes, enhancing security.
⚙️Setting Up Jenkins Master-Slave Architecture
Pre-requisites
Let’s say we’re starting with a fresh Ubuntu 22.04 Linux. To get an agent working make sure you install
Java (same version as Jenkins master server ) and Docker on it.
Prepare Master and Slave Node
Create two EC2 instances and name it
Jenkins-master
andJenkins-slave1
.Generate SSH keys on “Jenkins-master”
Generate SSH keys on
Jenkins-master
by running“
ssh-keygen
”. or if you face the SSH key format issue try withssh-keygen -b 1024 -t rsa
You can generate SSH keys on the slave node also and configure them accordingly.
Now goto
“.ssh
” folder and there will be public and private keys generated inJenkins-master
.
Configure Slave Nodes
Add public key from “
Jenkins-master
” to “Jenkins-slave1
” under location “.ssh/authorized_keys
”.
Connect Slave Nodes to Master
Go to the
Jenkins dashboard
, and click on “Manage Jenkins
”.Now, click on “
Manage Nodes and Clouds
”.Now, click on “
+ New Node
”.Enter the
Node name
and selectPermanent Agent
and click oncreate
.Enter the required details as per your requirement.
Make sure the
Remote root directory
you are specifying should be present in the slave node.Enter the
Labels
which is required.In the
Usage
Select as per your requirement I will select it hereUse this node as much as possible
.In
Launch method
Select as per your requirement I will select it hereLaunch agents via SSH
.In the
Host
enter yourJenkins slave node public IP address
.In
Credentials
Select your credentials or click onAdd
To add the credentials I willAdd( and click on Jenkins pop-up)
Here the new credentials.Select
Domain
as it is.In the Kind select
SSH Username with private key
.In the Username add what user you want to connect to the target server I will choose
ubuntu
as my target server user.Go to the Jenkins-master server in go to the
.ssh/
open theid_rsa
copy the secret key.In the
Private Key
SelectEnter directly
and click onAdd
.Enter/Paste
the secret key carefully and enter the passphrase If you provided at the time of generating and click onAdd
.Now select the newly created
credentials
.Add other required details and click on
Save
.Now you will see slave node is added.
Now click on the newly created slave node and click on
Launch agent.
Now, you can see the agent
Authentication successful
andAgent successfully connected and online
also connected to Jenkins master.
🏍Running the Job/Project at the Jenkins-slave1 node
Create a new project or you can tie the existing project with the Jenkins slave node.
Now, go to configurations in your task or project scheduled in Jenkins, Select
Restrict where this project can be run
and add the Label as same with the name of Node.Click on Save, and your project will be tied to
Jenkins-slave1
.On the Dashboard you can see the slave node is also added
Once you click on
Build now
the job will be executed byJenkins slave1 node
successfully.
🎉Conclusion
In this blog, we have seen how Jenkins master-slave architecture
is an efficient and scalable CI/CD pipeline. It empowers teams to distribute workloads, optimize resources, and enhance security, all while ensuring consistent and reliable builds and deployments. By understanding and implementing this architecture, development teams can achieve greater productivity and streamline their software delivery process.
Thank you🙏🙏... for taking the time to read this blog. I hope you found the information helpful and insightful. So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on
So, Stay in the loop and stay ahead in the world of DevOps!
Happy Learning !... Keep Learning ! 😊