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:
- Create 2 EC2 instances for master and agent
Jenkins-master:
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.
Generate SSH keys on “Jenkins-master” EC2 instance
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.
Let's create an agent by setting up a node on Jenkins
Go to the Jenkins dashboard, and click on “Manage Jenkins” then
Click on “Manage Nodes and Clouds”
To create a node click on "New Node" on left side
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