Day 28 Task: Jenkins Agents
In the realm of continuous integration and continuous delivery (CI/CD), Jenkins reigns supreme as the go-to automation server. But what truly elevates Jenkins to greatness? Enter Jenkins Agents, the unsung heroes of scalable and distributed builds.
Jenkins Master (Server)
Jenkins’s server or master node holds all key configurations. Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines. For example, scheduling a job, monitoring the jobs, etc.
Jenkins Agent
An agent is typically a machine or container that connects to a Jenkins master and this agent that actually execute 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.
A single, monolithic Jenkins installation can work great for a small team with a relatively small number of projects. As your needs grow, however, it often becomes necessary to scale up. Jenkins provides a way to do this called “master to agent connection.” Instead of serving the Jenkins UI and running build jobs all on a single system, you can provide Jenkins with agents to handle the execution of jobs while the master serves the Jenkins UI and acts as a control node.
Task-01
Create an agent by setting up a node on Jenkins
Create a new AWS EC2 Instance and connect it to master(Where Jenkins is installed)
The connection of master and agent requires SSH and the public-private key pair exchange.
Verify its status under "Nodes" section.
You can follow this article for the same
Step 1: Create two AWS EC2 Instance
You need to create two EC2 instances on AWS. One will be the master and the other will be the agent.
To create an EC2 instance, follow these steps:
Log in to your AWS console and go to the EC2 service
Click on the Launch Instance button
Choose Ubuntu as the AMI
Choose t2.micro as the instance type.
Configure the security group to allow inbound traffic on port 22 (SSH), port 80 (HTTP), and port 8080 (Jenkins)
Create or select an existing key pair and download the private key file (.pem)
Review and launch the instance
Step 2: Connect Master with Agent using SSH Keys
You need to establish a secure connection between the master and the agent using SSH keys. This will allow the master to authenticate and communicate with the agent without requiring a password.
Log in to your master instance using SSH.
Generate a public key for the master using
ssh-keygen
.Copy the public key of the master to the authorized_keys file of the agent.
Verify that you can log in to the agent from the master without a password using
ssh
.
Step 3: Install Jenkins on Master and Agent
Now, you have two EC2 instances connected by SSH keys, you need to install Jenkins on both of them. Jenkins requires Java to run, so you also need to install Java on both instances.
Step 4: Add Agent Node in Jenkins UI
In the Jenkins UI, navigate to "Manage Jenkins" > "Manage Nodes and Clouds."
Click on "New Node" to add a new agent.
Enter a name for the agent, select "Permanent Agent," and click "OK."
Step 5: Configure Agent Node
Set the number of executors (parallel job executions) for the agent.
In the "Remote root directory" field, specify the working directory on the agent.
Under "Launch method," choose "Launch agent via SSH."
Step 6: Add Credentials
In the "Credentials" section, click on "Add" to provide SSH credentials for connecting to the agent. Use the private key associated with the EC2 instance.
Step 7: Save and Connect
Save the agent configuration, and Jenkins will attempt to connect to the agent using the provided SSH credentials. Once connected, the agent status should change to "Online."
Task-02
- Run your previous Jobs (which you built on Day 26, and Day 27) on the new agent
- Use labels for the agent, your master server should trigger builds for the agent server.
Conclusion:
JenkinsAgents are the backbone of a scalable, distributed, and efficient CI/CD ecosystem. By harnessing the power of agents, organizations can accelerate software delivery, improve collaboration, and achieve greater agility in today's fast-paced development landscape. So, embrace Jenkins Agents and embark on a journey towards automation excellence!
Subscribe to my newsletter
Read articles from Vaishnavi Shivde directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vaishnavi Shivde
Vaishnavi Shivde
Aspiring DevOps Engineer | Linux | Git & Github | Shell Scripting | Docker | CI/CD Jenkins | Kubernetes | AWS | Terraform | JIRA | Python |