Day 28 - Unlocking Jenkins Agents ๐Ÿš€๐Ÿ”‘

Nilkanth MistryNilkanth Mistry
3 min read

Understanding Jenkins Agents

๐Ÿ–ฅ๏ธ Jenkins Master (Server):

  • The Jenkins master server orchestrates all workflows and configurations. It schedules jobs and monitors their execution.

๐Ÿค– Jenkins Agent:

  • An agent is a machine or container connected to the Jenkins master, responsible for executing job steps. Each agent is assigned a unique label for identification.

Scaling with Jenkins Agents

๐Ÿ“ˆ Scaling Up:

  • As project requirements grow, scaling becomes necessary. Jenkins facilitates this through master-to-agent connections, allowing distributed job execution.

Pre-requisites

๐Ÿ”ง Preparing the Environment:

  • Start with a fresh Ubuntu 22.04 Linux installation.

  • Ensure Java (same version as Jenkins master) and Docker are installed.

๐Ÿ› ๏ธ Setting Up Agents:

  • Agents need to be set up with separate rights, permissions, and ownership for Jenkins users.

Task-01: Creating Jenkins Agents

๐Ÿš€ Step 1: Prepare EC2 Instances

  • Launch two EC2 instances on AWS: one for the Jenkins master and the other for the agent. Name them accordingly (e.g., Jenkins_master and Jenkins_agent).

      sudo usermod -aG docker $USER 
      sudo usermod -aG docker jenkins
    

๐Ÿ”’ Step 2: Set Up Jenkins and Docker on Master

  • Install Jenkins and Docker on the Jenkins_master instance.

  • Add both your user and the Jenkins user to the Docker group for permissions.

๐Ÿ”‘ Step 3: Generate RSA Key Pair

  • Access the terminal on the Jenkins master server and generate an RSA key pair using ssh-keygen.

  • Retrieve the public key from the master server for later use.

๐Ÿ”— Step 4: Add Master's Public Key to Slave

  • Copy the master server's public key and paste it into the authorized_keys file on the Jenkins_agent.

  • Ensure the file is properly saved and exit the text editor.

๐Ÿ”— Step 5: Verify Connection

  • Attempt to SSH into the Jenkins_agent from the Jenkins_master to confirm successful connectivity.

๐Ÿ–ฅ๏ธ Step 6: Set Up Jenkins Agent

  • In the Jenkins dashboard, navigate to "Manage Jenkins" > "Nodes" and create a new node for the agent.

  • Provide details such as description, remote directory, host IP, and credentials.

  • Configure the node settings, including the number of executors, remote root directory, labels, launch method (SSH), and host address.

  • Select the appropriate private key for authentication and choose the "Non verifying verification strategy" for host key verification

๐Ÿš€ Step 7: Launch the Agent

  • Finally, click "Launch agent" to establish the connection between the master and slave.

With these steps, you've successfully set up a Jenkins master-slave architecture, enhancing your automation capabilities! ๐ŸŽ‰

Feel free to customize and elaborate on each step based on your specific setup and requirements. Happy blogging! ๐Ÿš€๐Ÿ”‘๐Ÿ”—

Task-02: Running Jobs on the New Agent

๐Ÿš€ Executing Previous Jobs:

  • Trigger builds for jobs created on Day 26 and Day 27 on the new agent.

  • Use labels to direct the master server to trigger builds on the agent.

  • Ensure the job runs on the slave machine. Save the pipeline configuration and execute it.

๐Ÿ” Troubleshooting:

  • If encountering any issues, seek assistance from DevOps groups, Discord, or Telegram communities.

Reflecting on the DevOps Journey

๐ŸŒŸ Happy Learning:

  • Keep up the enthusiasm and dedication to continuous learning! ๐Ÿš€

By following these steps, you'll successfully set up Jenkins agents, enabling distributed job execution and scalability in your CI/CD pipelines. Happy learning and coding! ๐ŸŽ‰๐Ÿ› ๏ธ

0
Subscribe to my newsletter

Read articles from Nilkanth Mistry directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nilkanth Mistry
Nilkanth Mistry

Embark on a 90-day DevOps journey with me as we tackle challenges, unravel complexities, and conquer the world of seamless software delivery. Join my Hashnode blog series where we'll explore hands-on DevOps scenarios, troubleshooting real-world issues, and mastering the art of efficient deployment. Let's embrace the challenges and elevate our DevOps expertise together! #DevOpsChallenges #HandsOnLearning #ContinuousImprovement