WebServer on Kubernetes Cluster via Jenkins (Groovy Script approach)

Ashish Kumar
4 min readJun 19, 2020
Jenkins + Kubernetes

This task has been completely implemented on RHEL 8. It is assumed that Jenkins, Minikube and Kubectl are already set up on your system.

**The kubectl is set up on host OS that will control our minikube. Minikube is available in VM. Host OS and Minikube are on a common network.

Jenkins Job list:

  1. Seed Job: This job is configured with a webhook. It will download the groovy script pushed by developers and create jobs and views as required by the operations team.
  2. The created jobs in our case have been specified to us and will be explained in the solution itself.

SOLUTION:

Plugins required to be installed:

  1. Job DSL
  2. Script Security Plugin
  3. GitHub plugin
  4. Workspace Cleanup Plugin (to clean workspace before every build)
  5. CloudBees Docker Build and Publish plugin
  6. Email Extension Plugin
  7. Build Pipeline Plugin

GitHub plugin and use of webhooks can be found here :

SEED JOB:

This a seed kob attached to a webhook. It will run every time a developer pushes an update. Here we are given what these jobs will perform which are as follows:

Job1: Download and interpret the code from Github, build the image using given Dockerfile and push it to Dockerhub.

Job2: Deploy and expose your webserver on Kubernetes so testing can be performed accordingly.

Job3: Send status to the team as per the result of the build and deployment status.

Seed Job Configuration

This job will not run directly so we need to tweak somethings in the security settings so we don’t face any problems.

Manage Jenkins >> Configure Global Security

This will disable security checks on DSL scripts else on every build you will have to approve the script.

After you build it, you get three new jobs and a new view in Build Pipeline. (Build Pipeline has a known bug, it won’t show the build pipeline until you change its name on every build. It would be created just not visible.)

Seed Job — Build Successful
Jobs and Build Pipeline View

** The jobs in the view will be visible after you start first build.

The code is available here for your reference.

This is the documentation I referred to write my codes. Refer here for help and if you have any doubts, contact me.

Now after we run the main jobs, here are the outputs on the first deployment and update rollout.

Deployment stages
E-Mail Notifications

Thanks for giving time. All doubts and suggestion are welcome.

Worked in collaboration with Daksh Jain.

Connect me on my LinkedIn as well.

--

--

Ashish Kumar

Just a tech enthusiast… Research, implement and share is what I like to do