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

Image for post
Image for post

Description:

  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 start the 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 the 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 the 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.

Tools used:

  1. Windows as base OS
  2. RHEL8 in which we run docker
  3. GitHub
  4. Kuberenetes
  5. Jenkins

Solution:

First we import the files ca.crt,client.crt,client.key and config file from the base OS to the folder in which we create Dockerfile in the RHEL8.

We create Dockerfile that has Jenkins and kubectl installed for launching pods on top of kubernetes.

Image for post
Image for post

Dockerfile:

Image for post
Image for post

We build the Dockerfile using the below command:

After successful build the following screen appears

Image for post
Image for post

After successful we will launch the container from this image with the following command:

After successful launching of container we can see that Jenkins got started in the 8083 port and enter the password that is provided at the time of launching the container

Image for post
Image for post

JOB1:

This job will copy the code from github into the workspace of job1 inside Jenkins container.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Job1 Output:

Image for post
Image for post

Job2:

This Job will run the Kubernetes pod with the required interpreter

Image for post
Image for post
Image for post
Image for post

Use the see the pvc.yml file and pod.yml files code in my Github repository

Job2 Output:

Image for post
Image for post

Job3:

This Job will open the site and if it is not working good then it sends mail to the developer.

Image for post
Image for post
Image for post
Image for post

Output:

Image for post
Image for post

Pipeline:

Image for post
Image for post

Thank You…

Written by

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