Boosting Jenkins Performance: Master-Server Setup Guide for Seamless Automation with Jenkins Agents

Boosting Jenkins Performance: Master-Server Setup Guide for Seamless Automation with Jenkins Agents

Introduction:

Enhance your Jenkins automation game by setting up a high-performance master-server configuration with Jenkins agents. In this guide, we'll walk you through the process of optimizing your Jenkins environment for efficient and scalable continuous integration.

This blog will be fully focusing on how to create agent , how to set credentials for agent etc. The prerequisite for this would be jenkins-server instance should be up running your jenkins on port 8080. On your local host kindly download the required things such as docker.io, docker-compose etc.
Also set the permission settings such as

sudo usermod -aG docker ubuntu
or
sudo usermod -aG docker jenkins
or
sudo usermod -aG docker $USER

Before building your pipeline make your dockerHub credential in advance in order to get your pipeline build for jenkins-server successfully as shown below.

Launch one more instance for "jenkins-agent" , do the same process for prerequisites as done on jenkins-server such as downloading the required things , setting the correct permission for users.

Coming to local host for both server and agent,

cd .ssh

to get into ssh and when you do ls there will be a file called "authorized_keys".

On "jenkins-server"

ssh-keygen

What is ssh-keygen ?

ssh-keygen is a command-line utility used to generate, manage, and manipulate SSH (Secure Shell) key pairs for secure communication between systems. SSH keys are cryptographic keys that provide a secure way to authenticate and establish a secure connection between two computers, typically for remote login and file transfer.

After this command, there will be several files downloaded into your local instance "jenkins-server" such as id_rsa , id_rsa.pub (public).

Note:

This same process of going into ssh folder will be done into "jenkins-agent".

cd .ssh

//There will be a file authorized_keys

sudo vim authorized_keys

//There will be the key present , go to bottom and paste the id_rsa.pub 
// of "jenkins-server" into this file and save it.

After saving it, exit the ssh folder in "jenkins-agent" and make it new directory of "jenkins-workspace" where all the git files and folder will be cloned.

Connecting agent instance from master instance

Taking the agent public ip such as 57.4.2.31 and writing a code into "jenkins-server" local host as

ssh ubuntu@57.4.2.31

Congrats! Now you can access the agent instance through master instance.

SetUp Agent

Head on to dashboard, click on manage jenkins there will be a popup for setup agent as displayed below.

Kindly name your node and select that radio button and create it.

Before moving forward, kindly direct to github on Jenkinsfile to change the agent name as displayed below from "agent any" to "agent { label "dev-server" }". Commit the changes of your github to save your changes.

Fill in the following details asked to create the agent.

Note the remote root directory means the folder we created on local host "jenkins-agent" named jenkins-workspace.

Get into that folder

cd jenkins-workspace
pwd
//take that file location and paste it into remote root directory

Label is very important as the changes you made onto the github Jenkinsfile , the same name goes here which you edited before.

host would be the public ip address for jenkins-agent instance.

Create a new credential , here dockerHub credential would be of no use.

The key is taken from localhost of "jenkins-server" into ssh folder from id_rsa file.

//jenkins-server
cd .ssh
sudo cat id_rsa

copy that key and paste it here as shown below.

Kindly click add, select the latest credential you made for this agent from dropdown menu.

Again head to jenkins dashboard, go to node-todo-cicd and build again. After successfull build you will get the following stage view like this.

open the port 8000 ipv4 on "jenkins-agent" security in edit-bound rules.

Direct to new tab and paste the jenkins-agent public ip of instance and Hurray! You will see your web application running on your agent.

Conclusion:

You've just unlocked the full potential of Jenkins by setting up a master-server configuration with agile Jenkins agents. Turbocharge your continuous integration and delivery processes with this optimized setup for unparalleled performance!

Champions keep playing, no matter how tough the game gets.

Did you find this article valuable?

Support CodeAryan by becoming a sponsor. Any amount is appreciated!