Dynamic Jenkins cluster along with Kubernetes
Saranya Chattopadhyay
Full Stack Developer - DevSecOps @IBM ? DevOps Practitioner ? Ex Intern @CommVault, HighRadius ? 2x GCP, 1x Microsoft, 1x RedHat Certified Engineer
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:-
Dockerfile for WebOS setup:-
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
The dynamic allocation of Jenkins slaves will be done from: Manage Jenkins --> Manage Nodes and Clouds --> Configure Clouds
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.
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:-
Output of Job-1:-
After the image has been successfully pushed, we can view it in our DockerHub repository.
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.
When JOB-2 will be run for the 1st time, it will create the deployment and expose it to public world. Output:-
On running the job further, it will just rollout the deployment. Output:-
Our webpage will deployed on:-
https://<minikube ip>:port no from job-2 In my case- https://192.168.99.100:31355
That's all about this task. Thank you all!!
A COLLABORATIVE PROJECT BY SARANYA CHATTOPADHYAY AND SAPTARSI ROY