DevOps(Day-28) : Setup a Jenkins Agent in Master

DevOps(Day-28) : Setup a Jenkins Agent in Master

Let's first understand what is Jenkins Agent and Jenkins Master.

Jenkins Master

The Master is the server that manages and builds the code. 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.

The basic installation of Jenkins operating alone is called a “master” or “controller.” The controller handles all tasks for your build system in this configuration. A “slave” or “agent” is a computer that’s set up to offload build projects from the master. Once set up, this distribution of tasks is fairly automatic.

The Jenkins controller schedules projects, assign agents/nodes and send builds to agents to execute projects. The controller will also monitor the agent state (offline or online), receive build result responses, and display build results on the console output.

Jenkins Slave(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.

Pre-Requisites

  1. Spin up two AWS EC2 instances.

  2. One of the servers should be Master and the other should be Agent.

  3. Install Jenkins, Docker, and Docker-compose on both servers.

Note:- While creating an agent, be sure to separate rights, permissions, and ownership for Jenkins users.

Task-1: Create an agent by setting up a node on Jenkins

  • Log in to the Agent server and generate the ssh key by running the below command.

    $ ssh-keygen

  • Take the ssh key from the id_rsa.pub file and paste it into the authorized_keys folder of the Master server.

  • Navigate to the Master server Jenkins page and click on Manage Jenkins and then Manage Nodes and Cloud.

  • Click on the new node to edit the configuration.

  • Provide the configuration details as shown below.

  • In the Launch method section Hostname should be the agent public Ip and the credential should be the key generated in the agent server as mentioned in the above step.

    Click on Save.

  • Verify its status under the "Nodes" section.

Task-2: Configure a new Agent to a pipeline

Let's configure the node-to-app to a new agent.

  • Let's navigate to the todo project and select Configure. Provide agent name as shown below.

  • Click save and build now.

  • Check the console output of the pipeline.

  • Navigate to the URL and check.

    We have seen the application of the Master-Slave configuration.

    Thanks for reading my article. Have a nice day.

    You can follow me on LinkedIn for my daily updates:- linkedin.com/in/bandan-kumar-sahoo-131412203