Day 28 Task: Jenkins Agents
Jenkins Master (Server)
Jenkins’s server or master node holds all key configurations. Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines. For example, scheduling a job, monitoring the jobs, etc.
Jenkins Agent
An agent is typically a machine or container that connects to a Jenkins master and this agent that actually execute all the steps mentioned in a Job. When you create a Jenkins job, you have to assign an agent to it. Every agent has a label as a unique identifier.
When you trigger a Jenkins job from the master, the actual execution happens on the agent node that is configured in the job.
A single, monolithic Jenkins installation can work great for a small team with a relatively small number of projects. As your needs grow, however, it often becomes necessary to scale up. Jenkins provides a way to do this called “master to agent connection.” Instead of serving the Jenkins UI and running build jobs all on a single system, you can provide Jenkins with agents to handle the execution of jobs while the master serves the Jenkins UI and acts as a control node.
Pre-requisites
Let’s say we’re starting with a fresh Ubuntu 22.04 Linux installation. To get an agent working make sure you install Java ( same version as jenkins master server ) and Docker on it.
Note:- While creating an agent, be sure to separate rights, permissions, and ownership for jenkins users.
Deploy web app using Jenkins master and worker node.
Here we will deploy a web app through Jenkins master to Jenkins worker node.
Step-1: Create 2 EC2 instances Jenkins-master & Jenkins-agent.
Step-2: Generate SSH keys on “Jenkins-master” by running “ssh-keygen”
Step-3: Now go to “.ssh” folder and there will be public and private key in Jenkins-server.
Step-4: Add public key from “Jenkins-master” to “Jenkins-agent” under location “.ssh/authorized_keys”
Step-5: Now, go to the Jenkins dashboard, click on “Manage Jenkins” and click on "Nodes and cloud".
Step-6: Now, click on “+ New Node”
Step-7: Add details of your second node, accordingly.
Step-8: Now click on “Ok”, and the node will be connected and online.
Step-9: Now, go to configurations in your task or project scheduled in Jenkins, and add the Label as same with the name of Node.
Step-10: Click on Save, and your project will be tied to Agent-01 and then build your project.
Step-11: Now, the web app will be up and running on “Jenkins-agent” and can be accessible via:
<ip of Jenkins agent:8000>
"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.
Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/ for the latest updates and discussions.