Integrating Kubernetes and Dynamic Jenkins Cluster

3 min readJul 26, 2020


Create A dynamic Jenkins cluster and perform task-3 using the dynamic Jenkins cluster.
Steps to proceed as:

1.Create container image that’s has Linux and other basic configuration required to run Slave for Jenkins. ( example here we require kubectl to be configured )
2. When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
3. Create a job chain of job1 & job2 using build pipeline plugin in Jenkins
4. 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 )
5. 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.

Lets Begin!!

First we have to create the docker image for jenkins slave In which we have already configured the kubectl to connect to kubernetes

docker build -t k8s-slave:1

Now we have to make some changes in docker configuration file so that anyone can connect with the docker at a particular port.

vim /usr/lib/systemd/system/docker.service

Open the file and edit it

After editing the file we have to run following commands

systemctl daemon-reload
systemctl restart docker

Now we have to create the Dockerfile of httpd server.

We have created this Dockerfile so that Jenkins will build an Image for webserver.

Now we have to manage Jenkins so that it can manage its slave nodes. For it Jenkins need Docker plugin, so first install it.After Installing we we go to configure cloud to configure the jenkins slave.

Now we are ready to create jenkins job

Job 1:

In this job jenkins will pull from the github that has Dockerfile and codes.Then It will build the docker Image for the webserver and push it to Docker hub.

JOb 2:

Job2 will create the dynamic slave node .then It will diploy the pods as per the requirements.