Dynamic Jenkins cluster along with Kubernetes

Dynamic Jenkins cluster along with Kubernetes

Hello world! Here goes our next article....

This article brings up the procedure of setting up a dynamic Jenkins cluster for kubernetes that will build an image for webpage deployment and setup that webpage automatically on the top of Kubernetes. So let's start the work.

Our first step will be to create the Dockerfiles needed. We would require two images - one that will have kubernetes setup and kubectl configured. Another image would setup our webpage containerised in an image.

Dockerfile for Kubernetes setup along with the folder structure:-

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

Dockerfile for WebOS setup:-

No alt text provided for this image

In order to deploy the whole setup on Kubernetes, we would need a kubernetes manifest file as follows:-

apiVersion: apps/v1
	kind: Deployment
	metadata:
	   name: webdeploy
	   labels:
	     app: webdeploy
	spec:
	   selector:
	     matchlabels:
	         app: webdeploy
	   replicas: 1
	   template:
	     metadata:
	         labels:
	            app: webdeploy
	     spec:
	         containers:
	         -  image: saranya2405/webimage
	            name: webdeploy
	            ports:
	            -  containerPort: 80
	               
                   name: webdeploy 

Next, we need to configure docker for slave-node architecture. For this, we need to make the following change (as highlighted) in root directory: /usr/lib/systemd/system/docker.service

No alt text provided for this image

The dynamic allocation of Jenkins slaves will be done from: Manage Jenkins --> Manage Nodes and Clouds --> Configure Clouds

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

Now, we are all set to start building our Jenkins Jobs.

JOB-1: This job will pull the Dockerfile (for webOS) along with the HTML code and manifest file from GitHub. It will build an image based on the Dockerfile and push the same to a public repository DockerHub.

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

Note: We need to make sure that before pushing our image to DockerHub, we have logged into the same from base OS (RedHat) using the command:-

No alt text provided for this image

Output of Job-1:-

No alt text provided for this image

After the image has been successfully pushed, we can view it in our DockerHub repository.

No alt text provided for this image

JOB-2: This job will create a deployment for our webpage on the top of Kubernetes using the manifest file uploaded and expose this deployment to the public world. Now, suppose the developer wishes to make certain changes in his code and after making the changes pushes it to GitHub. In that case, this job will automatically rollout the webpage with literally zero downtime and restart the deployment, so that users ( clients) never face any setback while using/viewing the website.

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

When JOB-2 will be run for the 1st time, it will create the deployment and expose it to public world. Output:-

No alt text provided for this image

On running the job further, it will just rollout the deployment. Output:-

No alt text provided for this image

Our webpage will deployed on:-

https://<minikube ip>:port no from job-2

In my case-
https://192.168.99.100:31355

No alt text provided for this image

That's all about this task. Thank you all!!

A COLLABORATIVE PROJECT BY SARANYA CHATTOPADHYAY AND SAPTARSI ROY


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

Saranya Chattopadhyay的更多文章

社区洞察

其他会员也浏览了