A Comprehensive Guide to Master-Agent Setup using Non-verifying Verification Strategy.

A Comprehensive Guide to Master-Agent Setup using Non-verifying Verification Strategy.

ยท

4 min read

In this blog post, we shall delve into the process of establishing a seamless connection between the master and agent node. So, without further ado, let us commence by configuring an AWS EC2 instance. If you require guidance on setting up an AWS EC2 instance, worry not, Click here.

To establish a robust Jenkins environment, it is essential to configure two instances, each with distinct roles. The first instance will serve as the host for the Jenkins master, orchestrating the CI/CD processes. Meanwhile, the second instance will act as the host for the Jenkins agent, executing tasks assigned by the master. Notably, Jenkins will be operational on the master server, facilitating efficient management and coordination of the entire CI/CD workflow.

Let's kick things off by starting the instances and launching Jenkins on the master server using the default port 8080, which is tailor-made for Jenkins. Now, to establish that all-important connection between Jenkins and the agent, we'll generate a key on the master host. This key serves as the key to unlocking the seamless connection between the two Jenkins and the agent.

Use the below command on the master host to generate a key.

ssh-keygen -t ed25519

And you'll see a key in your .ssh directory on the master host.

id_ed25519 is the private key and id_ed25519.pub is the public key. we need to copy the public key under the .ssh/authorized_keys on the agent's machine.

Copy the above id_ed25519.pub under the .ssh/authorized_keys on the agent's machine.

Now use the below command on the master to connect with the agent.

ssh <hostname_of_agent>

You can get the hostname of the agent by using the hostname command on the agent's machine.

Congratulations!๐ŸŽ‰ You are now successfully connected with the agent. Here's how it works: The private key on the master's machine is matched with the public key that we've copied under the .ssh/authorized_keys on the agent's host. This seamless matching process establishes a secure and reliable connection between the two, making your CI/CD setup smooth and hassle-free.

Now, let's take those keys and forge a connection between Jenkins and the agent's host. It's quite straightforward: the agent's machine holds the public key, while we'll hand over the private key to Jenkins's host. This mirrors the same scenario we had between the master and the agent, ensuring a seamless and secure connection. With this setup in place, Jenkins can effortlessly orchestrate tasks on the agent, streamlining your CI/CD process like a well-oiled machine.

To give the private key to Jenkin's host we'll go to Manage Jenkins corner.

Then select the Credentials option.

And click on the Add Credentials button.

A form will appear like this.

Select the SSH username with private key from Kind Dropbox.

The scope will remain Global (Jenkins, nodes, items, all child items, etc.) ID is important as this credential will be denoted by its ID. Give some ID, description, and username.

And you'll find a checkbox there with the name Enter directly. Where you can directly enter the private key that we generated earlier.

At last click on Create.

The final key will somehow look like this.

After the credentials are created, we need to set up an agent on Jenkins so that it can be assigned tasks by the master. To create an agent click on the Build Executor Status.

Now click on the New Node button.

Give some name to the node and select the Type as Permanent Agent. And click on Create.

There will appear a form in front of you to give some description, keep the Number of executors as 1, and give the path to the Remote root directory(working directory for agent).

Labels are important as the agent will be recognized by the labels. Give some label, and keep the usage as "Use this node as much as possible", select the launch method as "Launch agents via SSH". Give the Host IP of the agent in the Host field, Lastly, select the credentials from the Credentials dropbox that we have created above and go with "Non verifying Verification Strategy" under the Host Key Verification Strategy.

Leave the rest of the fields as default and click on Save.

Once you've saved the agent details, brace yourself for a seamless experience! With a quick redirect to the "Nodes" section, you'll witness your agent shining brightly on the node dashboard. There, you can effortlessly monitor and manage your agent's activities, unlocking a whole new level of efficiency in your CI/CD journey. Refresh the page to find your agent's Clock difference as "In sync," showing perfect alignment with the master.

To access detailed agent logs, click on the agent and head to the logs section. There, you'll find a reassuring message saying, "Agent successfully connected and online." Dive into the comprehensive logs for valuable insights and ensure your agent is operating flawlessly on Jenkins. Happy exploring! ๐ŸŽ‰


Note: Jenkins is written in Java, so we need to install Java on the agent's host for a reliable connection.

ย