Jenkins Master and Agents for DevOps Engineers

Jenkins Master and Agents for DevOps Engineers

#90DaysofDevOps Challenge - #Day28

▶How to set Jenkins Master and Agent Nodes

  • Jenkins Controller(Master)

The Jenkins controller is the Jenkins service itself and where Jenkins is installed. It is also a web server for deciding how, when, and where to run tasks. Management tasks such as configuration, authorization, and authentication are executed on the controller, which serves HTTP requests.

Files written when a Pipeline executes are written to the filesystem on the controller unless they are off-loaded to an artefact repository.

  • Nodes

They are the "machines" on which build agents run. Jenkins monitors each attached node for disk space, free temp space, free swap, clock time/sync, and response time.

A node is taken offline if these values go outside the configured threshold.

Jenkins supports two types of nodes:

built-in node

The built-in node is a node that exists within the controller process. It is possible to use agents and the built-in node to run tasks.

However, running functions on the built-in node is discouraged for security, performance, and scalability reasons.

The number of executors configured for the node determines the node’s ability to run tasks. The best practice is to set the number of executors to 0 to disable running functions on the built-in node.

  • Agents

It manages the task execution on behalf of the Jenkins controller by using executors.

An agent is a small (170KB single jar) Java client process that connects to a Jenkins controller and is assumed to be unreliable.

An agent can use any operating system that supports Java. Any tools required for building and testing get installed on the node where the agent runs.

Because these tools are a part of the node, they can be installed directly or in a container, such as Docker or Kubernetes. Each agent is effectively a process with its own Process Identifier (PID) on the host machine.

In practice, nodes and agents are essentially the same but it is good to remember that they are conceptually distinct.

  • Executors

An executor is a slot for the execution of tasks.

It determines the number of concurrent Pipeline stages that can execute at the same time.

Determine the correct number of executors per build node must be determined based on the resources available on the node and the resources required for the workload.

When determining how many executors to run on a node, consider CPU and memory requirements, as well as the amount of I/O and network activity like:

  • One executor per node is the safest configuration.

  • One executor per CPU core can work well if the tasks running are small.

  • Monitor I/O performance, CPU load, memory usage, and I/O throughput carefully when running multiple executors on a node.

▶ Pre-requisites for this hands-on

We are using a fresh Ubuntu 22.04 Linux installation on an AWS Free Tier EC2 instance.

To get an agent working make sure you install Java (same version as Jenkins Master server)

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

P.S. - On the Agent server, you only need to install the same version of Java and Docker installed on Jenkins Master)

▶ Task1

Create an agent by setting up a node on Jenkins

Create a new AWS EC2 Instances and connect it to Master(Where Jenkins is installed)

The connection of the Master and Agent requires SSH and the public-private key pair exchange.

Steps:

  • Create 2 AWS Free Tier EC2 instances for Master and Agent

  • On Master installs Java, Jenkins and Docker

  • On Agent installs Java and Docker.

  • Generate SSH keys on the “Jenkins-Master” EC2 instance

Add this public key from the Master instance to the Agent instance under location “.ssh/authorized_keys”

  • Create an Agent instance by setting up a node on Jenkins

  • Go to the Jenkins dashboard, click on “Manage Jenkins” then Click on “Manage Nodes and Clouds”

  • To create a node click on "New Node" on left side

At the newly opened window, follow the settings from the below screenshots:

Adding a name to your New Node.

Do not forget to add the new credentials to Jenkins adding the previously Private Key.

Checking the status of the New Node connection.

If everything goes fine, you will have this state of the New Agent.

▶ Task2

Steps:

  • Run your previous Jobs on the New Agent.

  • Go ahead to build your project, check the console output and test your deployed app.

In this hands-on, the app deployed is running on the Jenkins Agent instance IP on port 8000.

Thank you for reading. I hope you were able to understand and learn something helpful from my blog.

Please follow me on Hashnode and on LinkedIn franciscojblsouza