🚀Day 28 Task: Jenkins Agents😃

🚀Day 28 Task: Jenkins Agents😃

Jenkins Master (Server)

Jenkins’s server or master node holds all key configurations. 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 that actually execute 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

1) Create a new AWS EC2 Instance and connect it to master(Where Jenkins is installed)

-> Make EC2 instance that name should be 'master Jenkins'. and make sure you install java in that. steps are given below

  • Sudo apt-get update

  • Sudo apt-get install openjdk-11-jre

    2) Create an agent by setting up a node on Jenkins

    -> Make EC2 instance that name should be 'Jenkins agent'. and make sure you install java in that. steps are given below

    • Sudo apt-get update

    • Sudo apt-get install openjdk-11-jre

3) The connection of the master and agent requires SSH and the public-private key pair exchange.

Master node you can connect with terminal and generted key to connect agent node

1) ssh-keygen

2) cd .ssh

3)ls

4)copy master public key cat id_rsa.pub

5) Now go to agent node and paste public key into authorized_keys

6) In master open jenkins and create new agent.

7) Give a proper name and and click on 'permanent agent' and Click on create.

8) Fill the all fill as shown in below screenshot

9) create Credentials for jenkins

10)Select kind as “SSH username with private key”. Enter desired information in the mandatory fields: ID, Description, Username.

11) After clicking on “Add”, you need to give private key of master in the text box. So for this, go to master instance, do “cat id_rsa” and copy private key.

12) Enter the copied master’s private key in the text box and click on Add button. and last click on add button and select this key in Credentials

13) Your agent is made.

Thank you for your valuable time.

See you in the next task with a new blog. Happy Learning:)