Jenkins Dynamic Provisioning

Jenkins Dynamic Provisioning

Objectives

In this article , We will see how we can create dynamic slave on the fly when job come and attach to the jenkins master . So that all the job run on the slave . These slave are docker container . So it will be super fast...

Why we need dynamic slave ?

  • Initially we don't know how many slave nodes are required . So if we use static provisioning , then it will increase the cost . Because static nodes are continuously consuming RAM/CPU and other resources.
  • So we need dynamic provisioning . By this, we get slave node on the fly when demand comes and automatically terminated when it's work completed.

Now let's understand about jenkins

What is Jenkins ?

  • Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.
  • Jenkins is written in Java with plugins built for Continuous Integration purposes. Jenkins is used to building and testing your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.

Let' Started

We need two system :-

1. Jenkins Master

2.Linux (Rhel -8) System

No alt text provided for this image

In Rhel-8 system , we installed docker . Now when any job comes in Jenkins , then it contact to docker and launch the container (or slave). And this container terminated automatically after finished the job.

For better understanding , I divide this task in steps.

Step-1 Install Plugins in Jenkins

As we know , jenkins by default don't know about Docker. To gives this ability , we need to install docker plugin in jenkins master system

No alt text provided for this image

Note-

1. Make sure to disable firewalld in both the systems

2. Enable agent port in Jenkins master

Go to Manage jenkins -> Configure Global security -> Enable Agent port

No alt text provided for this image

Step-2 Enable TCP socket in Docker system

  • By default , docker engine don't have ability to control externally. But we want jenkins connect to docker . So we have to enable TCP socket in docker system(Rhel-8).
  • For this , open docker service file /usr/lib/systemd/system/docker.service and add -H tcp://0.0.0.0:2376 in the file .

No alt text provided for this image
No alt text provided for this image

This is socket binding. Now restart systemd daemon and docker service.

systemctl daemon-reload

systemctl restart docker        

Now docker can be manage locally and externally. Here I use 0.0.0.0:2376 . So if IP of jenkins master change , then we don't need to edit this file again and again.

Step-3 Add docker information in Jenkins Master

  • Now configure the slave in jenkins master . For this Manage Jenkins -> Manage Nodes and Cloud -> configure clouds -> Add a new cloud -> Docker
  • We get two section :- a. docker cloud details b. Docker agent templates

Click a. docker cloud details -> In this we add docker system ip

No alt text provided for this image
# Add this 
Docker Host URI = tcp://192.168.43.31:2376
        

b. Docker agent template

# Add this
Label = mydockerarth

Name = myslave

Image = vimal13/jenkins-slave-maven

Usage = Only build job with label expression matching this node  
        
No alt text provided for this image

We need an image that contains java and jenkins agent . So that jenkins master can contact to the container(slave). So i use an image vimal13/jenkins-slave-maven . This is also contain maven pre-installed . So we can able to run any maven related job.

Step-4 Run Jenkins Job

In this video , I show you the demo how slave node (container) is launched on the fly when demand comes and automatically terminate the slave(container) when job is finished.


Moshi Choudary

Windows System Engineer at Deloitte

2y

Hi, which course do you recommend to learn jenkins?

Like
Reply

To view or add a comment, sign in

More articles by Deepak Sharma

  • OSPF Routing Protocol using Dijkstra Algorithm

    OSPF Routing Protocol using Dijkstra Algorithm

    Objectives:- In this article, We will learn about Dijkstra Algorithm and Open Short Path First(OSPF) Routing Protocol .…

    1 Comment
  • MongoDB Case study: Forbes

    MongoDB Case study: Forbes

    Objective In this article , we see how MongoDB Cloud Migration Helps World's Biggest Media Brand Continue To Set…

  • Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    In this article, I am going to show you how you can create CNN Model or Deep Learning Model for Vehicle’s Number Plate…

    8 Comments
  • K-means Clustering and its real use cases in security domain

    K-means Clustering and its real use cases in security domain

    Objectives:- In this article, we will see about the Kmean algorithm and how Kmean algorithm helps in security domain to…

  • JavaScript:- Industry Use-cases

    JavaScript:- Industry Use-cases

    Objective In this article , we will learn about the JavaScript and the use-cases of JavaScript. How Industries utilizes…

  • Confusion Matrix and Cyber Security

    Confusion Matrix and Cyber Security

    Objectives:- In this article , we will see about confusion matrix and the use of confusion matrix . Also we see how…

  • Self-Reflection of MongoDB-Workshop

    Self-Reflection of MongoDB-Workshop

    # Day1 (1st May 2021) 👉 Introduction of the file system? 🎯The data we will stored in file and that file we basically…

  • OpenShift case study:- Cisco

    OpenShift case study:- Cisco

    Cisco’s success depends on its ability to quickly deliver innovative IT products and solutions to customers. Delays can…

  • Industry Use cases of Jenkins:- Prepl

    Industry Use cases of Jenkins:- Prepl

    In 2021, When industries are running towards automation, adopting different DevOps tools to solve their industrial…

  • AWS SQS Case Study:- NASA

    AWS SQS Case Study:- NASA

    “We now have an agile, scalable foundation on which to do all kinds of amazing things. Much like with the exploration…

Insights from the community

Others also viewed

Explore topics