Jenkins Agents (Part-5)

Kishor ChavanKishor Chavan
4 min read

Let's delve deeper into Jenkins Agents within the Master-Slave Architecture.

What exactly do these Agents entail, and how do they function within the broader framework of the Master-Slave Architecture in Jenkins?

Jenkins Master (Server)

The heart of Jenkins lies within its server or master node, housing critical configurations. This master server operates as a centralized control hub, orchestrating the defined workflows within pipelines. Think of it as the conductor overseeing tasks like job scheduling and continuous monitoring of processes.

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 within Jenkins is essentially a link or container that interfaces with the Jenkins master, responsible for executing all the specified tasks within a Job. When setting up a Jenkins job, it's crucial to assign it an agent, each of which is marked with a unique label.

When you initiate a Jenkins job from the master, the execution takes place on the agent node specified within that particular job configuration.

Initially, a comprehensive Jenkins setup might suffice for a smaller team with a limited project count. However, as requirements expand, scalability becomes imperative. Jenkins offers a solution known as "master to agent connection." This approach involves allocating agents to Jenkins, allowing them to manage job executions, while the master focuses on serving the Jenkins interface and overseeing operations as a control center.

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

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 the master and agent requires SSH and the public-private key pair exchange.

Verify its status under "Nodes" section.

Steps:

  1. Create 2 EC2 instances for master and agent
  1. Jenkins-master:

  2. Jenkins-agent:

In Jenkins master, we need Java,Jenkins, docker and docker-compose.

In 'Jenkins-agent' instance install java (same version like Master -Jenkins) docker and Docker-compose. No need to install Jenkins on agent node.

  1. Generate SSH keys on “Jenkins-master” EC2 instance

  2. Add public key from “Jenkins-master” instance to “Jenkins-agent” instance under location “.ssh/authorized_keys”

copy ed-key.pub from jenkins-master instance:

to Jenkins-agent .ssh/authorized_keys

we copied ed-key.pub from Jenkins-master to Jenkins-agent.

  1. Let's create an agent by setting up a node on Jenkins

    1. Go to the Jenkins dashboard, and click on “Manage Jenkins” then

    2. Click on “Manage Nodes and Clouds”

    3. To create a node click on "New Node" on left side

    4. Add details of your node, accordingly.

Create new credentials as below and save setting.

Now we could see our node added in our jenkins.Will test the connection with using the relaunch button on node.

we can see agents were successfully connected and sync.

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.

    - solution

    We invoke Jenkins-agent (labeled Jenkins-Agent) in our previous pipeline using the label name in our Jenkinsfile as below. and run the pipeline.

    Pipeline setting like below.

    Post build, we could see our pipeline completed.

    Could see agents and Jenkins files details in the console output.

    I trust we've clarified the concept of the master-slave architecture in Jenkins, where the master node assigns tasks to the slave or agent node for execution, minimizing the inherent risks of inbuilt execution and freeing up CPU resources for additional tasks. This optimization not only enhances Jenkins' performance but also ensures smoother task execution.

    Thanks,

    Kishor Chavan

0
Subscribe to my newsletter

Read articles from Kishor Chavan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kishor Chavan
Kishor Chavan

With a rich history spanning decades in Industrial IT, I currently serve as a Technical Consultant at onshore. My career has been defined by my unwavering commitment to DevOps and leadership in database administration projects. Cloud Expertise: I possess extensive knowledge and hands-on experience in the realms of Microsoft Azure and AWS Cloud. I've played a pivotal role in architecting and optimizing cloud solutions that enable businesses to scale, innovate, and thrive. Cloud DB and DevOps Advocate: My pursuit of excellence never stops. I'm on a constant quest to acquire deep knowledge in Cloud Database solutions and DevOps tools. From Azure DevOps to Jenkins, Ansible to GitHub, Terraform to Docker and Kubernetes, I'm committed to staying at the forefront of industry trends. I'm passionate about leveraging technology to drive success in industrial IT. Let's connect and explore how my decades of experience and expertise can contribute to your organization's growth and transformation.