Day 28: Elevating Jenkins: Unleashing Maximum Potential through Master-Agent Collaboration🚀🚀

Day 28: Elevating Jenkins: Unleashing Maximum Potential through Master-Agent Collaboration🚀🚀

Day#28 Of 90 Days Of DevOps Challenge

💥Introduction

Jenkins stands as a widely used open-source automation server, facilitating the automatic building, testing, and deployment of code.

Within the Jenkins framework, the pivotal notion of master and agent nodes plays a crucial role in the efficient distribution of work tasks.

Serving as the central coordinating hub, the Jenkins master server governs task orchestration, while its counterpart, the Jenkins agent or slave, is entrusted with executing the actual jobs.

The purpose of this article is to provide a step-by-step walkthrough for the configuration of a Jenkins agent.

The process encompasses establishing a connection between the agent and the Jenkins master, followed by a confirmation of its operational status.

💻Jenkins Master

The Jenkins master server is the core component that manages configurations, scheduling jobs, and monitoring tasks.

It acts as a control server that coordinates workflows defined in pipelines. The master node handles interactions with agents, scheduling jobs to be executed on them, and collecting results afterward.

🖥Jenkins Agent

A Jenkins agent is a machine or container that connects to the Jenkins master server. Agents are responsible for executing the steps outlined in a Jenkins job. When creating a Jenkins job, it's necessary to assign an agent to it. Each agent is labeled to provide a unique identifier.

When a Jenkins job is triggered from the master, the execution takes place on the agent node specified in the job configuration. This distribution of work ensures that the master node doesn't get overwhelmed and can focus on controlling the overall process.

For teams with growing needs, Jenkins offers the ability to scale using a "master-to-agent connection." This approach allows agents to handle job execution, while the master concentrates on serving the Jenkins UI and managing the workflow.

📃Prerequisites

Before setting up a Jenkins agent, you need to ensure that you have the following prerequisites in place:

  1. Fresh Ubuntu 22.04 Linux Installation: Start with a clean Ubuntu 22.04 Linux installation as the base for your Jenkins agent.

  2. Java Installation: Install the same version of Java that is used on the Jenkins master server. This is essential for compatibility between the master and agent.

  3. Docker & Docker-Compose Installation: Docker/Docker-Compose is also required on the agent machine. It enables the creation and management of containers, which can be used to isolate job environments.

Note: When creating the agent, pay attention to user rights, permissions, and ownership to maintain security and avoid conflicts.

📖Task 01: Create a Jenkins Agent Node

In this task, we'll guide you through the process of creating a new AWS EC2 instance and connecting it to the Jenkins master as an agent node.

  1. Create an AWS EC2 Instance

    • Launch a new EC2 instance on AWS using the desired Ubuntu 22.04 AMI.

    • Configure security groups and networking settings as needed.

  2. SSH Key Pair Exchange

    • To establish a connection between the Jenkins master and the agent, you need to exchange SSH key pairs.

    • Generate an SSH key pair on the Jenkins master if you haven't already:

        ssh-keygen
      

    • Go to the “.ssh” folder and copy the public key content from the generated key pair :

        cat ~/.ssh/id_rsa.pub
      

    • On the agent machine, add the copied public key to the ~/.ssh/authorized_keys file.

  3. Configure Agent Node in Jenkins-Master

    • In the Jenkins UI, go to "Manage Jenkins" > "Manage Nodes and Clouds" > "New Node."

    • Provide a name for the node, select "Permanent Agent," and click "OK."

    • Configure the agent settings, including the number of executors, remote root directory, labels, etc.

    • Specify the agent launch method (SSH) and provide the necessary credentials.

  4. Verify Agent Status

    • After saving the agent configuration, Jenkins will attempt to connect to the agent using the provided SSH credentials.

    • In the Jenkins UI, navigate to "Manage Jenkins" > "Manage Nodes and Clouds."

    • You should see the newly added agent listed with its status indicating whether it's online and available.

📚Task 02: Run a Jenkins Job on Agent Node

  1. As we have seen in Day 27 blog about the declarative pipeline project, here we will be deploying the same in the agent node.

  2. The difference will be here in the pipeline script i.e. agent: we have specified the agent on which we want to deploy.

    1. Now access the deployed app with the agent-node IP Address and Port in the browse

✨Conclusion

Embracing the synergy between Jenkins masters and agents amplifies automation potential.

By efficiently distributing workloads, this collaboration optimizes CI/CD pipelines for enhanced productivity and scalability.

Mastering this connection empowers seamless, powerful automation.

As we continue our #90DaysOfDevOps Challenge journey, remember that Jenkins Pipelines are just one part of the vast DevOps landscape.

Embrace the opportunity to learn and apply new concepts, tools, and practices.

Thank you for joining us on this exciting Day 28 of the challenge. 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 :

Hashnode: vishaltoyou.hashcode.dev

LinkedIn: linkedin.com/in/vishalphadnis

So, Stay in the loop and stay ahead in the world of DevOps!

Happy learning 🚀😊🐧📦🔧🛠️💻💼🔍📈🚀🌟📊📚