Day 11: Jenkins Agents

Day 11: Jenkins Agents

Hello Everyone!

I learnt about agents in jenkins. Please find my below notes. Hope it will be useful

Agents

In Jenkins, an agent refers to a machine that is set up to run build jobs. An agent can be a physical machine or a virtual machine, and it is managed by the Jenkins master server.

Let's say I have a master Jenkins server with 8 GB has 3 jobs. Example Django , Node js , Java application. Each application requires 10 gb, 30 gb and 50 gb. These applications cannot be run in the master server as it is only has 8 gb.

This master server is linked with 3 agents with 16 gb , 32gb, 64 gb each. As master cannot run those 3 jobs agents will run the jobs based on requirement.

Agent 1

Agent 2

Agent 3

These are labels

All the jobs will be present in the master. Agents can connect to the master thru SSH.

In order to connect with agents, java should be installed in these agents.

Master will allocate the agents to run the jobs.

Steps

  1. To connect agent with the master, we need to first Add the credentials.

    Go to credentials and add private key of master jenkins server in it and save.

  2. Make sure that agent server is having java installed in it to connect.

  3. In the agent server also add public key of the master jenkins server.

  4. Configure the agent node by giving agent ip address, lable to be identified with,root home directory (like home/ubuntu/jenkins-agent-server)this will automatically be created in jenkins agent server. Non verification strategy.

  5. Launch the agent to connect

  6. When you are trying to deploy the application in master jenkins, then agent will deploy the application. So make sure to install all the necessary softwares installed in the agnet server.

Setting up agent in Jenkins

Dashboard - Manage Jenkins - Nodes - New node

I have a master instance (Jenkins server). I will create a new instance (agent -1).

Connecting agent with master

Creating agent in master jenkins

To connect agent with master, you need to ssh.

In master we will generate ssh keys which consists of private key and public key.

Public key will be given to agent

private key will be in master.

In master server:

id_rsa -- private key

id_rsa.pub -- public key

agent-1

We will add public key of master in agent-1 authorized keys.

Add this below public key in the above file

added public key of master in agent-1 in vim authorized keys file.

open jenkins and

👉 give agents ipaddress as host

👉give private key of master (because jenkins is running on master)

Add master private key in jenkins. Host name is agents IP address

We wont be able to connect to the agent because there is no java installed in agent1.

Install java in agent1 and launch agent

Agent deploying app

Lets try deploying application in the agent.

I created a node to do app job.

Make sure that docker, docker compose are installed in agent server.

now build the application.

you can see that this application is handled by the agent.

You can see that our app is now present in agent server.


--Thank you for your time. Happy Learning--