INTEGRATION OF KUBERNETES WITH MASTER-SLAVE ARCHITECTURE OF JENKINS

INTEGRATION OF KUBERNETES WITH MASTER-SLAVE ARCHITECTURE OF JENKINS

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

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

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.

apiVersion: apps/v1
	kind: Deployment
	metadata:
	 name: myweb-deployment
	spec:
	 replicas: 3
	 selector:
	  matchLabels:
	   env: web
	 template:
	  metadata:
	   name: myweb-pod
	   labels:
	    env: web
	  spec:
	   containers:
	   - name: myweb-con
	     image: mansh/phpweb:v1
         imagePullPolicy: always
	     

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

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/manmohan2823/Devops-jenkinscluster.git

Now here comes the beautiful build pipeline...

No alt text provided for this image

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



要查看或添加评论,请登录

Manmohan .的更多文章

社区洞察

其他会员也浏览了