Day 28 of #90daysofdevops
Hey Techies! Welcome to this blog
In this blog, we are going to start the Jenkins Agents.
Jenkins Master (Server)
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. 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 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.
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.
Key Features of Jenkins Agents:
Parallel Execution: Agents enable parallel execution of tasks, significantly reducing the overall build and deployment time.
Workload Distribution: Agents distribute the workload across multiple machines, preventing bottlenecks and optimizing resource utilization.
Platform Diversity: Agents can run on different operating systems and environments, allowing Jenkins to accommodate a variety of project requirements.
Scalability: Adding more agents to your Jenkins setup is a straightforward way to scale your CI/CD pipelines and accommodate growing workloads.
Isolation: Agents operate independently, providing a level of isolation for tasks. Failures on one agent do not affect others.
Types of Jenkins Agents:
Permanent Agents: These agents are configured to be always online, waiting for tasks from the master. Permanent agents are suitable for stable and consistent workloads.
Cloud Agents: Cloud agents are created dynamically based on demand. Jenkins can spawn agents in cloud environments (such as AWS, Azure, or Google Cloud) and terminate them when the workload decreases.
Docker Agents: Jenkins can utilize Docker containers as agents, providing a lightweight and reproducible environment for executing tasks.
Pre-requisites
Let’s say we’re starting with a fresh Ubuntu 22.04 Linux installation. To get an agent working make sure you install Java ( same version as jenkins master server ) and Docker on it.
Note:- While creating an agent, be sure to separate rights, permissions, and ownership for jenkins users.
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.
Configure SSH for Master-Agent Communication
On the Jenkins master, generate an SSH key pair:
ssh-keygen
Copy the public key (~/.ssh/id_
rsa.pub
).
On the Jenkins agent, open the authorized_keys
file and paste the public key.
Configure Jenkins Agent on Agent Instance
Once Jenkins is running on the master, navigate to "Manage Jenkins" > "Manage Nodes and Clouds."
Click on "New Node" and enter a name for your agent.
Select "Permanent Agent" and click "OK."
Configure the following:
Remote root directory: Leave it as is or specify a custom directory.
Labels: Add any labels you want for this agent.
Launch method: Choose "Launch agent via Java Web Start."
- Add credentials.
In 'Key', give the private key you generated in the master server.
Click "Save" and then "Launch Agent" to start the connection.
Check the status of your new agent under "Manage Nodes and Clouds."
Use this agent to run your pipeline
- We'll use a simple 'Hello-World' example. Use the below pipeline script.
pipeline {
agent { label 'dev-server'}
stages{
stage('Build') {
steps{
echo 'Hello World'
}
}
}
}
Congratulations! You've successfully set up a Jenkins master and agent on separate AWS EC2 instances, creating a distributed CI/CD environment. This architecture allows you to efficiently scale your Jenkins pipelines, enhancing your overall development and deployment processes.
That's it! You've just completed the task. 🎉
Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.
Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.
Happy Learning!
~kritika :)