Table of contents
No headings in the article.
Welcome back, tech enthusiasts! Today, we're delving into the fascinating world of Jenkins Agents โ a crucial component in scaling up your Jenkins environment for larger projects and teams. Let's dive right in!
Understanding Jenkins Master and Agents:
๐ข Jenkins Master (Server): At the heart of Jenkins lies the master server. This is where all the key configurations reside. Think of it as the control center orchestrating all the workflows defined in your pipelines. From scheduling jobs to monitoring their execution, the Jenkins master server handles it all.
๐ป Jenkins Agent: An agent, on the other hand, is like a dedicated worker bee. It's typically a machine or container that connects to the Jenkins master and executes the steps defined in a job. Whenever you create a Jenkins job, you'll need to assign an agent to it. Each agent is identified by a unique label.
๐ Master to Agent Connection: As your projects and teams grow, a single Jenkins installation may not suffice. That's where the master to agent connection comes in. Instead of burdening the master with both UI serving and job execution, agents take on the latter, while the master focuses on control and management.
Pre-requisites:
Before we dive into the hands-on part, let's ensure we have everything set up:
๐ง Fresh Ubuntu 22.04 Installation: We'll start with a clean Ubuntu 22.04 Linux installation. Make sure you have Java (same version as your Jenkins master server) and Docker installed on it.
๐ SSH and Key Pair Exchange: The connection between the master and agent requires SSH and the exchange of public-private key pairs. Make sure this is set up correctly.
๐ Separate Rights and Permissions: When creating an agent, it's crucial to separate rights, permissions, and ownership for Jenkins users to ensure smooth operation.
Task-01: Setting Up an Agent Node
Let's set up Jenkins with a master and an agent using AWS EC2 instances. This involves creating two instances: one for the Jenkins master and another for the agent.
For the Jenkins master instance, we'll need to install Java, Jenkins, Docker, and Docker-compose. On the agent instance, we'll install Java (the same version as on the master), Docker, and Docker-compose, but Jenkins isn't necessary.
Next, we'll generate SSH keys on the Jenkins master instance and add the public key to the Jenkins agent instance's authorized_keys file. This allows secure communication between the master and the agent.
Once the setup is done, we'll head over to the Jenkins dashboard, navigate to "Manage Jenkins," and then "Manage Nodes and Clouds." From there, we'll create a new node by providing the necessary details.
We'll also create new credentials for the node and save the settings. This ensures secure communication between the master and the agent.
Finally, after adding the node, we'll test the connection by relaunching the node. If everything goes well, we'll see that the agents are successfully connected and synchronized with the master.
Task-02: Running Jobs on the New Agent
Let's tackle Task-02 by running our previous jobs, which were built on Day 37 and Day 38, on the new agent. To achieve this, we'll utilize labels for the agent, allowing our master server to trigger builds for the agent server.
In our solution, we'll configure our Jenkinsfile to invoke the Jenkins-agent labeled as "Jenkins-Agent" in our previous pipeline. This is done by specifying the label name in our Jenkinsfile.
We'll set up our pipeline accordingly in the Jenkins configuration. Post-build, we'll monitor the completion of our pipeline to ensure successful execution.
Upon completion, we'll review the details of the agents and Jenkins files in the console output to verify the process.
This exercise reinforces the understanding of the master-slave architecture in Jenkins. Here, the master node delegates tasks to the slave or agent node for execution, optimizing performance and resource utilization. This approach not only enhances Jenkins' efficiency but also streamlines task execution for smoother workflow management.
Stay tuned for more tech adventures! Until next time, happy building! ๐โจ