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 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.
Prerequisites -
We should have one Jenkins master server.
We need one agent server with Docker and Java installed (same version as of master server).
Ubuntu user should have Docker permission to run the Docker commands.
Task-01
Create an agent by setting up a node on Jenkins
Create a new AWS EC2 Instance and connect it to the 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 the "Nodes" section.
Steps :
- Create keypairs using the ssh-keygen command on Jenkins master server
- Copy the public key and paste it into the authorized key of the Jenkins agent server for SSH authentication.
Note: You can check the connectivity by doing ssh from master to agent manually.
Create an agent node from Jenkins web UI -
Manage Jenkins > Nodes > New Node > Give a node name.
Follow the below steps as per the screenshots
Give root directory
Launch agent method - Launch via SSH
We need to create credentials for SSH authentication.
Add new credentials and give the private key of the master server.
Host key verification strategy - Non-verifying strategy.
Save it, the node should be online.
If it's offline then repeat the steps, check if the ssh connectivity is working or not and any other possible mistake.
The node is up.
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.
Go to the Day 27 job > Configure > Update the pipeline with label - dev (which we had given while creating the agent node)
Build completed successfully -
The console output will show the name of a node - I created a node with the name Day28-task. (The pipeline ran on agent node).
Thank you :)