Web Server with Live Updates Roll Out using Jenkins and Kubernetes

Ashish Kumar
May 30, 2020 · 5 min read

This task will help us deploy a Web Server using Distributed Jenkins where a dynamic slave will deploy the webserver on Kubernetes. Jobs have been pipelined in such a way that either a new Deployment will be done and exposed else update will be rolled out on the already existing deployment of Web Server. The complete setup is automated and the pipeline will run every time a developer pushes any changes to the web page or for any configuration changes in the docker image. The update will be rolled out in such a way that downtime is not caused for the clients.

This task has been completed on:

  1. RHEL 8
  2. Docker-CE (Client — 19.03.10, Server — 18.09.1)
  3. Jenkins
  4. Git
  5. Kubectl will be set up on the dynamic slave
  6. MiniKube is set up Windows.

We will install the required plugins in Jenkins:

  1. GitHub
  2. Docker
  3. Workspace Cleanup

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. The steps for it can be found in a previous article of mine :

Moving on to the next step, the job will copy all the files inside the docker image to be built and then will be further pushed to Docker Hub. This all will be done using the Docker Plugin.

We need to allow docker daemon to be accessed remotely. For that, we need to edit /usr/lib/systemd/system/docker.service.

The following has been appended to ExecStart. You can bind it with any available port. 0.0.0.0 denotes any IP that will be given to the host.

Then restart the services.

So before using the Docker Plugin, we will set up the Docker Cloud on Jenkins.

Manage Jenkins > Manage Nodes and Clouds > Configure Clouds > Add A New Cloud — Docker > Set the required parameters > Test connection

Cloud Configuration

** Docker Host URI is the remote docker host where all the containers will run. In my case, I have set it on my localhost as well.

Save.

Now moving back to configuring the Job 1.

The workspace will be cleaned before every build and then pull the repository.

The Directory is default set to the workspace so it will auto pick the Dockerfile. Set image name and credentials and you are good to go.

The files used in the task are available at :

The pushed image is available at :

Job 2 will build on the successful build of Job 1. This job will create a new deployment if does not exist else it will rollout update to the existing deployment. This Job has to run on a dynamic container slave whose template will be configured on the docker cloud. First, we will build the image to be used via a Dockerfile.

Next, We will add Docker template in the Docker Cloud settings.

Docker Agent templates…

Docker Agent Template Configuration

Labels: This will be used in jobs to refer and call the specifically required slave.

Name: The Node Name that appears in Agents list.

Docker Image: The image used to create the slave container.

** In Container Settings, add the mount point where the files required for kubectl configuration are stored.

These files have been copied from windows where my MiniKube is set up and running as Virtual machine. And the config file has been set up accordingly.

These files are to be mounted at /root/.kube so that the configuration is setup globally.

Now moving on to the setup in job 2.

Job 1 Build Output

Job 2 Build Output

When no deployments:

Deployment exists, therefore rolling out updates:

Testing the webpage:

Worked in collaboration with Daksh Jain.

Connect me on my LinkedIn as well.

LinuxWorld Informatics Pvt. Ltd.

Making India, Future Ready!

LinuxWorld Informatics Pvt. Ltd.

LinuxWorld Informatics Pvt. Ltd.(‘LW’) is a fast-growing ISO 9001:2008 Certified Organisation, Fully governed by young & energetic technocrats, dedicated to Linux, Security & Open Source Technology…

Ashish Kumar

Written by

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

LinuxWorld Informatics Pvt. Ltd.

LinuxWorld Informatics Pvt. Ltd.(‘LW’) is a fast-growing ISO 9001:2008 Certified Organisation, Fully governed by young & energetic technocrats, dedicated to Linux, Security & Open Source Technology…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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