๐ Day 32: Setting Up Jenkins Agents! ๐ค
โ What is Jenkins? ๐ ๏ธ
Before we get into agents, let's quickly recap what Jenkins is. Jenkins is like a superhero for developers. It helps automate repetitive tasks, like testing and deploying code, making the life of a developer much easier. Think of Jenkins as a smart assistant that handles all the boring stuff for you.
โ Meet the Master and the Agents! ๐ฉ๐ฅ
In Jenkins, we have two main players: the Master and the Agents.
Jenkins Master (Server) ๐ฉ
Role: The boss that manages everything.
Tasks: Schedules jobs, monitors their status, and serves the Jenkins user interface (UI).
Think of it as: A conductor of an orchestra, making sure everyone is playing their part.
Jenkins Agent ๐ฅ
Role: The worker that does the actual job.
Tasks: Executes tasks defined by the Jenkins jobs.
Think of it as: A musician in the orchestra, playing the notes assigned by the conductor.
โ Why Do We Need Agents? ๐ค
For small projects, having just the Jenkins master might be enough. But as projects grow and you have more tasks, it's better to have multiple agents to share the workload. This way, jobs get done faster and more efficiently.
โ Let's Set Up an Agent! ๐ ๏ธ
To set up an agent, we'll use an AWS EC2 instance (a virtual machine in the cloud) with Ubuntu 22.04. Here's a step-by-step guide:
Step 1: Create an AWS EC2 Instance ๐ฅ๏ธ
Launch a New Instance:
Go to the AWS Management Console.
Launch a new EC2 instance with Ubuntu 22.04.
Choose an instance type like
t2.micro
(good for small tasks).Configure security settings to allow SSH access.
Connect to Your Instance:
Use SSH to connect to your instance. Open your terminal and type:
ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
Step 2: Install Java and Docker on Your Agent โ๐
Install Java:
Update your package list:
sudo apt update
Install Java:
sudo apt install openjdk-11-jdk -y
Install Docker:
Install Docker with:
sudo apt install docker.io -y
Start Docker:
sudo systemctl start docker sudo systemctl enable docker
Step 3: Connect the Agent to Jenkins Master ๐
Generate SSH Key Pair on Master:
On your Jenkins master server, generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C "jenkins-agent"
Copy the public key to your agent:
ssh-copy-id -i ~/.ssh/id_rsa.pub ubuntu@your-ec2-instance-public-dns
Set Up Jenkins Agent Node:
In Jenkins UI, go to Manage Jenkins > Manage Nodes and Clouds > New Node.
Enter node details and set up using SSH with the credentials.
Verify Agent Status:
- Check the "Nodes" section in Jenkins to see if the agent is connected.
โ Running Jobs on the New Agent ๐โโ๏ธ
Now that your agent is set up, let's run some jobs!
Step 1: Label Your Agent ๐ท๏ธ
Go to Manage Jenkins > Manage Nodes and Clouds > your-agent > Configure.
Add labels to your agent.
Step 2: Run Jobs ๐
Configure your jobs to use the new agent's label.
Run the jobs you built on Day 26 and Day 27 on the new agent.
โ Conclusion ๐
Setting up Jenkins agents helps distribute the workload, making your projects run smoother and faster. By following these steps, you've taken a big step towards mastering Jenkins! Keep up the great work, and see you tomorrow for more DevOps adventures! ๐
Feel free to ask any questions or share your progress. Let's learn and grow together! ๐ฑ
Happy DevOps-ing! ๐
Subscribe to my newsletter
Read articles from Ritesh Dolare directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ritesh Dolare
Ritesh Dolare
๐ Hi, I'm Ritesh Dolare, a DevOps enthusiast dedicated to mastering the art of DevOps.