CI/CD Pipeline Using Dynamic Distributed Cluster

1. Create a container image that 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:

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

4. 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:

5. 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.

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

In this step we need to create a container image that has Linux and other basic configuration required to run Slave for Jenkins.

I am using this Dockerfile to create the image.

kubectl confg file:

To create the image use this command:

docker build -t adyraj/kubernetes:v2 .

After creating this image we need to upload it to the docker hub.

Now we need to configure the docker service to docker daemon remotely. So for this first we need to enable the tcp socket connectivity in docker server.

After this we need to export DOCKER_HOST variable with server ip in client.

export DOCKER_HOST=SERVER_IP:4243

Now we need to configure the jenkins cloud for dynamic cluster.

In this step we need to create a job chain of job1 & job2 using build pipeline plugin in Jenkins

Job1 : In this job we need to create a new image dynamically and copy the application code into it and the push the image to the docker hub.

Dockerfile:

Console output of Job1

Job2 : In this job we need to launch the application on the top of Kubernetes cluster performing the operation specified in the task.

Console output of job2

Build Pipeline View:

This the we page.

Thank you !!!

--

--

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
Aditya Raj

Aditya Raj

I'm passionate learner diving into the concepts of computing 💻