Deploying Webserver On K8s Using Groovy

Rohan Khandelwal
4 min readMar 1, 2021

Perform previous task with the help of Jenkins coding file ( called as jenkinsfile approach ) and perform the with following phases:

  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. Job2 ( Seed Job ) : Pull the Github repo automatically when some developers push repo to Github.
  5. Further on jobs should be pipeline using written code using Groovy language by the developer.
  6. Job1 :
    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 using PVC ( If server collects some data like logs, other user information )
  7. Job3 : Test your app if it is working or not.
  8. 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.

Let’s Get Started:

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk.

Other Tools:

  • Git / GitHub -> Source Code Management & Version Controlling
  • Jenkins -> Automate software development related to deploying
  • Kubernetes -> container-orchestration system for automating application deployment, scaling, and management
  • Docker -> Container Engine Kubernetes will manage
  • RHEL8
  • Minikube on MacOS

We will start by setting up a GitHub repository. A Webhook is configured as well so that whenever a push is done, Job 1 build starts. When Developer changed something into GitHub then Jenkins Job-1 should be triggered automatically. For this, we have to create a webhook trigger on Github so that it automatically can trigger. But we have to remember one thing, Github belongs to the public world and my Jenkins is running into my RHEL8 which has private IP. So the Public world can’t connect to the private world. But we have one way. We can create a tunnel something like this so that the public world connect to my private world. ngrok is a software that I used to expose my private IP on the internet.

My entire setup is done on the top of RHEL8. First, we have to make change some changes in the docker service file.

systemctl daemon-reload
systemctl restart docker.service

The following plugins to be downloaded in Jenkins

  • job DSL
  • Cloudbees docker build and publish plugin
  • script-security plugin

Go to Manage Jenkins->Configure Global Security and disable script security.

Now we will be doing a seed job.

After you build it, you get three new jobs and a new view in Build Pipeline.

You have to manually build the job1, job2, and job3 respectively. After the successful build of these jobs, you’ll get the following outputs.

job1 output

job2 output

job3 output

EMAIL notification after successful built of job3

THANK YOU!

My Linkedin — Rohan Khandelwal

--

--