Step-by-Step Guide to Jenkins Master-Slave Configuration on AWS EC2

Boosting/Optimizing CI/CD Pipelines: Jenkins Master-Slave Configuration on AWS EC2

Step-by-Step Guide to Jenkins Master-Slave Configuration on AWS EC2

Jenkins, a leading open-source automation server, offers robust capabilities for continuous integration and continuous delivery (CI/CD) pipelines. To enhance its performance and scalability, Jenkins employs a Master-Slave architecture, which can be effectively implemented using Amazon Web Services (AWS) EC2 instances.

In simple word it’s like hiring someone to do your work. In our case we hire(another EC2 instance) to do the Jenkins build.

Pre-requisite

  1. AWS Account

  2. Basic Linux commands

  3. Basic Understanding SSH login.

  4. Github account

Master Slave Architecture

So, a master or host will have Jenkins server running (in our case it’s EC2 instance) i.e. the first step is to create EC2-instance which we will be calling as master node.

  1. Setup Master node

    Here I have spin-up a EC2 instance with name linux-jenkins (AMI as Ubuntu) and instance type as t2.micro.

  2. Connect to Instance

    The next I will be connecting to my master node to setup Jenkins their.

Setup Jenkins and Java version

After connecting, make sure you have git installed , check it using

git -v

now, I have a shell script ready to setup the Jenkins and a sample project of maven. you can find it here: Github-Link

  1. Setup Jenkins on Master node

    To setup Jenkins on our EC2-instance or master node, run the below commands

     >> git clone https://github.com/Dharansh-Neema/Setups
     >> cd Setups
     >> sh jenkins-ec2-ubuntu.sh
    

    The above commands we install Jenkins and make it running on port 8080. (default Jenkins Port)

    To access your Jenkins server : http://<public-ip-address>:8080

    Setup your Jenkins Server and you will see the Jenkins Dashboard like this :

  2. Setup Slave Instance

Now, we will spin-up EC2-Instance which we will out-source our work through SSH login. Here I have spin up a Ubuntu EC2 Instance name jenkins-slave.

Note: Slave doesn’t require JENKINS Installed.

yes, slave don’t require any Jenkins installed because we only want to use it’s system resource but a slave must all the library which project require, in our case it’s maven.

  1. Connect master and Slave using SSH

    Go to Jenkins Dashboard» manage Jenkins » Nodes» New Node , where it look like this :

    We already have built in node , we will add slave node, Click on New Node

  2. Provide this as config

    Change Launch Method to SSH Login

    Host : Give private IP address of the slave instance.

    Credential : Provide SSH credentials and if you don’t have one, then create it.

    Now click on save at the bottom.

  3. Slave Node

    As, you can we got our slave node, which we can use to build projects