Integrating Jenkins with Kubernetes

RAJNISH MISHRA
4 min readJun 14, 2020

We will do following things in the project

  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

I am not explaining the basics as I already have explained in my previous article.

Project

Dockerfile

We will create a Dockerfile using centos (Downloaded from docker hub). The image will have jenkins installed after it’s build.

Creating image

docker build -t jenos:v1 /ws/

/ws/ is directory in which Dockerfile is stored. We build our image using the Dockerfile.

Starting Container

docker run -it -p 9090:8080 jenos:v1

Configuring Jenkins

Assuming that user has some knowledge about jenkins, we will skip configuration of jenkins

WebUI Dockerfile

Pulling from Git repo and building image

Output

In this job we downloaded the code from github and copied it into base os and then into dockerfile to build image for testing.

Auto Detection of extension and launching container

This will detect the code and launch the respective

Testing

Testing team tests the code and if the code is not working properly the remote trigger this job using url and email is sent to developer about failure of the code.

If testing is successful the the deployment will run then the deployment will run as it is.

Note: I have already mentioned how to configure smtp and other steps for sending mail

Output

This webpage is designed by Mr. Mayank Sahu.

Suggestions are highly appreciated. In case of any queries, DM me or comment below

I have not gone in much detail as I already have discussed in earlier articles

You can read those from LinkedIn

Thank You for your valuable time

--

--