Integrating Jenkins and Kubernetes to Deploy website

ADARSH KUMAR
3 min readJul 26, 2020

--

We are going to deploy an infrastructure with all the powerful features of Kubernetes , like deployment,service,pvc to host a website.We are also going to use Jenkins for CI/CD.

Workflow:

1.Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7

2. When we launch this image, it should automatically starts Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins
4. Job1 : Pull the Github repo automatically when some developers push repo to Github.
5. Job2 :
1. By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code on top of Kubernetes ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed )
2. Expose your pod so that testing team could perform the testing on the pod
3. Make the data to remain persistent ( If server collects some data like logs, other user information )
6. Job3 : Test your app if it is working or not.
7. Job4 : if app is not working , then send email to developer with error messages and redeploy the application after code is being edited by the developer

Lets Begin!!

First we have to create Dockerfile for the Container Image that has jenkins pre-installed.

docker build -t jenkins:1

Now the jenkins Image is ready,so we have to launch jenkins container.

docker run -it -p 1234:8080 --name jenk jenkins:1

Now Our jenkins is running on the port 1234.

Job 1:

In this job we pull the data from GitHub, and copy it to our local repository.

Job 2 :

In this job ,jenkins first check the language of the code , It It has interpreter of it then It will launch deployment ,Service,and pvc on the kubernetes server to launch the website,If It don’t find the suitable Interpreter , It will show “ Code is not compatable”.

Job 2 will be automatically triggered after the successful build of job 1.

Job 3 :

Job 3 will be auto triggered after the successful build of job 2.In this job Jenkins will get the pod name from the kubernetes server, so that it can copy the website code to the pods, so that client can get the website.

Job 4 :

This job will also triggered by the successful build of job 3,This job is for testing, To test the website is live or not.If not then it will trigger a job that send mail to developer .

Job 5:

This job will be triggered if test fails.It will send the mail to developer.

Thank YOU!!

--

--