Dynamic Jenkins cluster

Ankit Prakash
3 min readOct 14, 2020

Task description

Create container image that’s has Linux and other basic configuration required to run Slave for Jenkins.

When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.

Create a job chain of job1 & job2 using build pipeline plugin in Jenkins

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

Create the new image dynamically for the application and copy the application code into that corresponding docker image
Push that image to the docker hub (Public repository)

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:

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.

1.Building a dockerfile

Since We need to require to run slave for jenkins we need to do two things:-

First set the Docker as slave from host.

Second we need the Dockerfile which has Kubectl configured to our minikube server, or server running kubernetes. Also exposing the ports required for the slave.

FROM centos CMD [“/bin/bash”]
RUN yum install java-11-openjdk.x86_64 -y
RUN yum install sudo -y RUN yum install git -y
RUN yum install httpd -y
RUN yum install initscripts -y
RUN yum install /sbin/service -y
RUN sudo yum install wget -y RUN curl -LO
https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"

RUN chmod +x ./kubectl
RUN mv ./kubectl /usr/bin/

COPY config /root/.kube/
COPY ca.crt /root/
COPY client.crt /root/
COPY client.key /root/
COPY config /root/.kube

EXPOSE 8080

2.Making Jenkins Slave To put it in slave node of Master Jenkins, configure cloud from Manage Jenkins. Provide the Label to the Slave so as to identify it.

After configuration

3.Creating the First job of Jenkins to fetch the github repo containing files for testing and also one addition job to push our jenkinslave docker imge to the docker hub

4.Running script on the slave where kubectl is configured.

Output:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Ankit Prakash
Ankit Prakash

No responses yet

Write a response