Dynamic Jenkins Cluster..

Dynamic Jenkins Cluster..

In this project I am going to create the End to End automation.. In this automation technologies i am going to use are Kubernetes , Jenkins , Docker , Github and Git..

About the Project..

Create A dynamic Jenkins cluster...

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. Job 1 : 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. Job 2 ( 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.

Now lets start doing the automation..

I have created a docker image using DokerFile that has kubeclt configure. Through this image i will launch a container that will work as slave node..

No alt text provided for this image

I have created one more image that has Web server configured..

No alt text provided for this image

Configuring the dynamic slave of Jenkins..

For making slave i have done some changes in dokcer sever. I have done changes in this file "/usr/lib/systemd/system/docker.service".

No alt text provided for this image

After doing above steps you have to reload daemon and restart the docker services. Command for reloading daemon " systemctl daemon-reload" and command for restarting docker services "systemctl restart docker"..

No alt text provided for this image

After doing above changes in docker services. I configured jenkins as a cloud server.. After this configuration jenkins will work as a client who will contact docker server..

No alt text provided for this image
No alt text provided for this image

JOB 1 : - In this job jenkins will download the code from github and create docker images of webserver and kubectl and then images will be uploaded to the dokcer hub.

Github link from where jenkins will download the code..

No alt text provided for this image

I have used PollSCM. As soon as developer push the code in github jenkins will contact to github and download the code..

No alt text provided for this image

Code that will create and upload the image on the docker hub..

No alt text provided for this image

JOB 2 :- In this job jenkins will launch a slave by using kubectl image and this slave will launch the deployment. And do rollout when developer will update something in their code..

For launching deployment i have created a "deployment.yml" file and copied it to the kubectl configration image.

No alt text provided for this image

I have restricted the Job2 to run on the dynamic slave of the jenkins.

No alt text provided for this image

Job 2 will only run when the job 1 will run successfully.

No alt text provided for this image

Code that will update the image and do rollout.

No alt text provided for this image

Now lets run the Job..

Before running the job i would like to mention one thing. In this project their is two cases.

Case1 :- If the deployment is already created then my job will only update the image and do the rollout.

Case2 :- If the deployment is not created then my job will create deployment and update the image and do rollout..

Finally lets run the Job..

No alt text provided for this image

Job 1 console output..

No alt text provided for this image

Job 2 console output when deployment is not created. (for better understanding read case 2).

No alt text provided for this image

Accesing the website in the chrome..

No alt text provided for this image

Now developer do some changes in the code. Highlighted line is the changes.

No alt text provided for this image

After doing the changes in the code Job will again run automatically and then the job will update the changes in the image and do the rollout..

Console output of job 2 when the deployment is already cretaed..

No alt text provided for this image

Now if i again acces the site in the chrome then you will see the site will updated with zero downtime.

No alt text provided for this image

Finally i have achieved the end to end automation with zero down time..

All the code you will get from the below link..

https://github.com/AJAY487-star/Devops-end-to-end-automation

Now here comes the beautiful build pipeline...

No alt text provided for this image

Thankyou people for giving your precious time for reading my article..





To view or add a comment, sign in

More articles by Ajay Kumar

  • Jenkins Installation by Helm...

    In this article I am going to show you how we can install JENKINS in the KUBERNETES by the help of HELM package…

    4 Comments
  • Industry use case of Ansible...

    What is Ansible ? Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration…

  • Industry Use Case On Kubernetes

    What is kubernetes ? Kubernetes is a portable, extensible, open-source platform for managing containerized workloads…

  • Industry Use-Case of Neural Networks

    Neural networks reflect the behavior of the human brain, allowing computer programs to recognize patterns and solve…

  • Machine Learning

    Machine learning is a technology that provides computers to think and learn like human beings. Machine learning focuses…

    4 Comments
  • AWS {Biggest cloud computing platform in the earth}

    Yes you have read absolutely right in the above heading AWS is the biggest cloud computing platform in the earth…

  • Integration Of Ansible with Docker.

    This is the First task of Ansible training..

    1 Comment
  • Jenkins Job automation using groovy..

    This is the 6th task of DevOps AL training given by Mr Vimal Daga sir..

  • Integrate Prometheus and Grafana..

    This is the 5th task of Devops AL training..

  • Automation using Kubernetes..

    This is the 3rd task of DevOps Assembly lines..

Others also viewed

Explore content categories