Automating Deployment with CI/CD pipeline using Jenkins with using the power of Kubernetes

Problem Statement

Tools Required

Start RHEL8 on your Virtual machine which is the host for docker. Create a folder which must have ca.crt, client.crt, client.key, and config file. Copy these files using WinSCP. These files are needed to Kubernetes in Docker containers.

Now we will create one Dockerfile that has Jenkins and kubectl installed for launching the pod on top of Kubernetes. In this Dockerfile, I have copied all the requirements used by kubectl to connect to the Kubernetes cluster. So when a container launch from this image, kubectl from the container can connect to Kubernetes cluster for launching the pods

Now built this docker image with this command

docker build -t jenkkube:v .

After the image has been built successfully then from this image we launch one container with the help of docker.

docker run -it --name task6os -p 1122:8080 jenkkube:v

After the container has been launched successfully, we can see that Jenkins has been started In this we have to keep the password that has been provided at the time of launching the container.

Now we will be creating the first job using Jenkins


This job will copy the code that is downloaded by Jenkins from GitHub into the workspace of job1 inside the Jenkins container.

JOB1 output


This job will detect code, either PHP or HTML, and run kubectl client container with the image created before and run Kubernetes pod with the required interpreter.

This job will run only when the first job builds successfully.

Here I am creating one YAML file for creating one PVC (Persistent volume claim) for the pod. when pod request for storage to PVC then PVC will get the storage from PV and provide to the pod and mount the folder of the pod. PV will create dynamically when PVC created.

Here I am creating YAML file for launching the pod on top of Kubernetes. This pod will run with the httpd image. When there is HTML code then pod with this image will launch. For making the data persistent attaching one PVC to a folder — /usr/local/apache2/htdocs

I have created both the YAML inside the /work folder in Jenkins container

First, Jenkins will check if the code is written in HTML then first creating one PVC for the pod through the YAML file after this launching one pod with httpd image through the YAML file. copy the code that Jenkins download from GitHub to the container running inside the pod. Expose this pod so that client can connect to the website running on this container inside the pod.

JOB2 Output


For email notification, we have to provide the following details for sending emails to the developer.

SMTP Server —

Default user e-mail suffix-

Smtp port — 465

user name and password of the email from which you want to send the email to the developer

Now in job 3

if this job fails means the site is not running fine. In this case, it sends mail to developer

In post-build actions → E-mail Notification-

recipients- email address of the developer



Creating one build pipeline for visualizing the chaining of the jobs



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store