Dynamic Clustering In Jenkins with docker, Kubernetes..
Here, we will get to know what actually is dynamic clustering in jenkins and how to implement it, what’s the use of it.
So, Dynamic clustering is the creation of cluster dynamically, when requirement came means when job is to be run and that job will run on dynamically created cluster on some another server. It will save our resources because when the job is done, cluster will be deleted automatically.
So let’s start it, what we’ll do today is:-
So first we’ll set up some configurations inside jenkins so that when requirement came, automatically cluster will create. For that we have to first install Docker plugin inside jenkins and afterwards:-
Manage jenkins -> Manage nodes and cloud -> Configure cloud -> Add a new cloud -> Docker
Here in above screenshot i have used the image which is said to be created in below point which have kubectl configured.
- 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 )
For this first we have to create dockerfile :-
docker build -t mansi1709/k8s:v1 .
docker push mansi1709/k8s:v1
2. When we launch the job it should automatically starts job on slave based on the label provided for dynamic approach.
We already did this configuration above.
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 )
Dockerfile for creating the image dynamically:-
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:
- 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.
Job 2 automatically started on the successful build of Job 1:-
So, now our final webpage can be accessed at 192.168.99.100:32525/my.html
So, we have done the task , Hurrah !!!
Thank you for reading !!
My github repo url:-