Jenkins Agents: Deploy web app using Jenkins master and worker node #Day 28
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 actually 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.
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
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 master and agent requires SSH and the public-private key pair exchange.
Verify its status under "Nodes" section.
You can follow this article for the same
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.
Pre-requisites:
-Java should be installed on both instances Jenkins-master and Jenkins-agent.
-Docker and Docker-compose should be installed on both instances Jenkins-master and Jenkins-agent
Points to be remembered:
ssh-keygen command will be run on Jenkins-master.
id_rsa.pub will be copied on Jenkins-agent at '.ssh' location under authorised.keys file
id_rsa will be copied and pasted under the private key section of Jenkins Credentials Providers while creating Agent Node on Jenkins-master Dashboard.
Steps:
Create two EC2-instance one for Jenkins-server and the other for Jenkins-agent (Slave)
Generate SSH keys on 'Jenkins-server' through 'ssh-keygen'.
Go to the .ssh folder to get generated public and private keys.
Copy <id_rsa.pub> key from the 'Jenkins-master' server and add it to Jenkins-agent at '
.ssh/authorized_keys
' location.Login to Jenkins-server Dashboard and go to Manage Jenkins.
Go to 'Nodes'
Click on +New Node and add details of the Jenkins-agent node
Add the private key of the Jenkins-master server at the private key option
Save and refresh the icon, the agent dev created.
Created a declarative pipeline job for node-todo-app
Deploy the code
Console output
Access deployed todo-app through Jenkins-agent ip.
"Thank you for reading my blog! Happy Learning!!!😊
Stay tuned for more DevOps articles and follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/namratakumari04/ for the latest updates and discussions.