Job on dynamic slave in jenkins

Jenkins: jenkins is the devops tool which helps to automation of projects , by which projects are tracked and done automatically. jenkins can be used as integration tool also . By jenkins many devops tool are integrated and done project in loop automaticaly without using more human resources .

When job is running on jenkins then cpu, ram and other hardware or software is used of that system where jenkins is running , due to this when more heavy job is running then system might be hang up . For avoiding this problem ,it is necessary to create distributed job cluster.

For creating distributed cluster one jenkins connect with two or more than two VM or OS via SSH in linux and via JNLP in windows .

The OS which gives service to jenkins for run job, that is known as worker/slave OS and the OS, over which jenkins is running is known as master OS.

Distributed cluster is of two types, static distributed cluster and dynamic distributed cluster.

When VM or laptop(windows/linux/mac OS ) are used as slave OS, then static distributed cluster is configured. But when docker container is used then dynamic distributed cluster is configured.

In dynamic distributed cluster automatically slave node is launched , when job is build , via SSH , job is run and then slave node is terminated .

For creating dynamic distributed cluster , first of it is necessary to do some setup .

docker can be managed by other OS also, when docker server is in one OS and docker client is in other OS , For this network have to be established between two VMs using tcp protocol .

The OS which support docker server is known as DOCKER_HOST .

The OS which support docker client is known as cloud Node .

For setup OS as docker server for accessing from other OS for dynamic node cluster , first of all network have to be set .

edit file “/usr/lib/systemd/system/docker.service”

this will exposed docker server , after edit file run cmd

systemctl daemon-reload
systemctl restart docker

Task description:

  1. Create container image that has linux and other basic configuration required to run slave for jenkins .
  2. When i launch the job then automatically start job on slave based on the label provided for dynamic approach .

job in jenkins:

Job1 : Pull the github repo automatically when some developers push repo to Github and perform the following operations as:

1. Create the new image dynamically for the application and copy the application code into that corresponding docker image

2. Push that image to the docker hub (Public repository)

( Github code contain the application code and Dockerfile to create a new image )

Job2 ( Should be run on the dynamic slave of Jenkins configured with Kubernetes kubectl command): Launch the application on the top of Kubernetes cluster performing following operations:

1. If launching first time then create a deployment of the pod using the image created in the previous job. Else if deployment already exists then do rollout of the existing pod making zero downtime for the user.

2. If Application created first time, then Expose the application. Else don’t expose it.

First of all, i have created a Dockerfile for creating dynamic slave .

mkdir devops_task4
cd devops_task4


docker build -t slave_image:v1 .
docker tag slave_image:v1 firsttalk26/slave_image:v1
docker push firsttalk26/slave_image:v1

now for creating dynamic distributed cluster jenkins is used, In jenkins “Docker” and “Yet Another Docker” plugin are required

Now go to “Manage jenkins>> Manage Nodes and Clouds>> Configure clouds


Execute shell:

sudo mkdir /root/devops_task4
cp -rvf * /root/devops_task4



Execute shell:

if kubectl get deployment | grep httpd-deployment
kubectl set image deploy httpd-deployment webserver=firsttalk26/httpd_image:v1 --record
kubectl apply -f httpd_deployment.yml
kubectl apply -f httpd_service.yml



Execute shell:

status=$(curl -o /dev/null -s -w "%{http_code}" [ $status == 200 ]
exit 0
exit 1





enthusiastic for new technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Fork Safemoon Contracts for Beginners

Day 10: Salesforce Custom Notifications #TexeiAdventCalendar

The date command is used to display the system date and time.

Kotlin @ 60FPS

How to create an AWS Lambda Authorizer for API Gateway

Week 2: Google Summer of code with Debian

Introducing Saturn-GQL: An Opinionated Way to Develop GraphQL API’s

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhiraj Kumar

Dhiraj Kumar

enthusiastic for new technologies

More from Medium

What Is Kubernetes Pods

Multi Maven & Git Repositories App Service Azure DevOps Deployment

Resilient CICD

[Study Notes] Docker