Automation using Kubernetes

Kritika Shah
4 min readJul 26, 2020

Task Description:

1. Create container image that’s has Jenkins installed using Dockerfile Or You can use the Jenkins Server on RHEL 8/7, When we launch this image, it should automatically start the Jenkins service in the container.

2. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins

3. Job1: Pull the Github repo automatically when some developers push repo to Github.

4. Job2 :

→ 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 HTML, then Jenkins should start the container that has HTML already installed )

Expose your pod so that testing team could perform the testing on the pod

→ Make the data to remain persistent ( If server collects some data like logs, other user information )

5. Job3: Test your app if it is working or not.

6. Job4 : If an app is not working, then send email to the developer with error messages and redeploy the application after code is being edited by the developer.

Firstly, We’re going to create Dockerfile for creating the image which will contain pre-installed Jenkins and Kubernetes services.

Run below command to build a Docker image using Dockerfile:-

docker build -t <image name>:<tag name> <path>

After Image has been created successfully then push that docker image on your Dockerhub account.

Now let’s come to Windows and deploy the Kubernetes cluster using Docker image which is created by us now.

Need some files to deploy the Kubernetes cluster automatically with just one-click.

  1. kubejenkins.yml is used to run Jenkins on top of Kubernetes by deploying clusters.
  2. The deployment.yml file used to deploy the Kubernetes clusters by using any image, for E.g. Httpd image used in my project to launch a web server on Jenkins.
  3. The pvc.yml is used to create Volume Claim because if we write anything in our pod and restart the pod, We will lose entire data, Hence we have to attach PVC to retrieve our data even if we delete or restart the pods.

Start the minikube.

kubectl create -f kubejenkins.yml

kubectl logs <podname>

Enter the password given above and install all recommended plugins and Build Pipeline plugin.

JOB 1: It’s a simple configuration to pull GitHub repo automatically in your workspace mounted on Kubernetes pod.

  • This is the most important job and will launch the webserver automatically by detecting HTML code inside the pods and launch the HTML container using httpd image.

JOB 2:This is the most important job and will launch the webserver automatically by detecting HTML code inside the pods and launch the HTML container using httpd image.

JOB 3: Simple testing job to check web server is working properly or not.

JOB 4: If WebApp is not working as status received from previous jobs then this Job should send mail to developer with entire build logs for the debugging phase.

Let’s create pipeline for monitoring all jobs.

Thankyou!!!!!

--

--