Table of contents
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.
Please follow the Day 27 task and Day 26 task blog. In this blog, you will see how the declarative pipeline works.
Task-01
Create an agent by setting up a node on Jenkins
Create a new AWS EC2 Instance and connect it to master(Where Jenkins is installed)
The connection of master and agent requires SSH and the public-private key pair exchange.
Verify its status under "Nodes" section.
You can follow this article for the same
Step 1: Create two instance master and worker like this
Step 2: Connect master two jenkins
Step 3: Click on setup agent
Step 4: Give a node name and tick on permanent agent and create
Step 5: Give description and Remote root directory as " /home/ubuntu "
Step 5: Give label as "dev" and Usage to " use this node much as possible" ans Launch method to " Launch agents via SSH " and copy Host as worker-server instance IP address like this and paste it their
Step 6: Now come to master-server instance terminal and go to cd .ssh/ then genterate ssh key by running commands
cd .ssh/
ssh-keygen
given any name to key here i have given server-key
here you can see two files have been created one is server-key which is the private key and another one is server-key.pub which public key.
Step 7: Go to server-key.pub
cat server-key.pub
and copy it then paste in worker-server terminal by going to .ssh/ run command
ls
here you can see one file which is aurthorized-keys
Step 8: Go inside aurthorized-keys by running commands
vim aurthorized-keys
Now you should see like this in your screen
Now press "i" in your keyboard and paste the master-server ssh public key like this
then press "esc" button then ":wq" to exit the vim editor
Step 9: now come to the Jenkins credentials section select Jenkins like this
now you will see like this page
Now in kind section select SSH username and private key
then set the ID, description and username shown in the image below
then select enter directly and Add like this
Step 10: Go to the master-server terminal and open ssh private key like this
cat srever-key
then copy it and past it in Jenkins credentials like this and add
Now credential add this
Step 11: In Host key verification strategy select this
and save
here you can see the both node is connected
task 01 is completed
Task-02
Run your previous Jobs (which you built on Day 26, and Day 27) on the new agent
Use labels for the agent, your master server should trigger builds for the agent server.
In case of any issues feel free to post on any Groups, Discord or Telegram
Recreate day 26 task in it
Step 1: create a new job and in the pipeline area write this commads and save
here you can see we have successfully runed out pipeline
Let's recreate days 27 task in it
Step 1: In GitHub project put the url like this
and run this command is pipeline section and save
pipeline {
agent {label "dev-agent"}
stages {
stage(code){
steps{
git url: "https://github.com/Gurucharan716/react_django_demo_app.git", branch: "main"
}
}
stage(build){
steps{
sh "docker build . -t react-django-app"
}
}
stage(run){
steps{
sh "docker run -d -p 8001:8001 react-django-app:latest"
}
}
}
}
Step 2: Now build now then you can see its successfully running
Step 2: Go to console output you can see this
Step 3: Go to worker server instance and open port 8001 like this
Step 4: Copy its IP address and add ":8001" to it
here you can see we have successfully deployed it through Jenkins pipeline
Now we have completed both task01 and task02 of day 28..
Thank you for reading this blog and if any queries or if any corrections to be done in this blog please let me know.
contact us in Linkedin ,Twitter or email-id gurucharanu716@gmail.com