Rolling Updates With Docker Jenkins and Kubernetes

Rolling Updates With Docker Jenkins and Kubernetes

Almost each and everything keeps improving and innovating in this world and this is necessary because if you don't, you will be kicked out of the market and this competition game but have you ever wondered how these companies updates their websites or webapps? If they do it directly then what about those who were doing some transactions at the time the company updated their website? Also, they need to have zero downtime as for the big MNCs if the system is down for even a few seconds, it is on the every news source the next day. An example for this is, WhatsApp Went down for 1 hour because of New Year wishes at midnight on New Year 2018 and it was on News everywhere.

So the question is, What's the solution? and How do they do it because We see new features being added and new updates everyday. I have tried to show a demo for this. The strategy used for these kind of updates where we do not disturb or interrupt the client already in our website is called Rolling Updates. We are going to use Kubernetes to deploy our Website and Manage it, if it goes down, Launch it again immediately and if any update is rolled out, do not interrupt the existing clients and let the enjoy the version of website they are on already and show the new updated website to the client who will visit after the update.

Step 1 :- Developer will write the website code and Dockerfile for the Docker image and push the code to Github. Create a webhook at Github to trigger the job of jenkins, So the setup will look something like this :-

No alt text provided for this image

Check the above shown Github Repository and my Dockerfile if you want.

Step 2 :- Setup jenkins for building the docker image and leave everything to it, it will handle all the things till deployment using Kubernetes.

We are going to Install a Plugin called docker to setup our jenkins master as docker client to build the image etc. and push it to docker hub so that our kubernetes can use it to deploy our website on the server. The setup after Installing the Plugin will look like :-

I have configured the docker service file at port 4243 and I have used the same in jenkins to configure is as docker client to run the commands at docker server

No alt text provided for this image

In the docker Agent template, we will use our own created docker image which will be launched to do our job of git clone and then deploy, for this We have built an image which has Git and Kubectl (client setup of kubernetes) installed and configured and we will mount the volume to the folder where we have our certificates as it can be critical to put those in the docker image and I have named the image as dheeth/gitkube, the dockerfile and kubectl config file of that image is shown below :-

No alt text provided for this image
No alt text provided for this image

Step 3 :- Configure a job in jenkins to clone the git repo and then build a docker image for us and push it to docker hub using the docker plugin, We will provide our credentials for the account to push the image and the label is used for the job to dynamically launch the docker container and run the job, Also, this job will be automatically triggered by the github webook if developer push any update, so it is just a one time setup. The setup will look like as shown in screenshots below :-

No alt text provided for this image
No alt text provided for this image

Output Console Logs of the job setup above are shown in the screenshots below :-

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 4 :- Configure another job and set it to trigger after the previous job, so that it will automatically create deployment using kubernetes and if any update is pushed, it will automatically rollout the update, We have set the label in this job too, for it to use our dynamic node from docker and do the job, It will use the image built in previous job to deploy our code on the webserver from the image. The job configuration is shown in the screenshots below :-

No alt text provided for this image
No alt text provided for this image

After this job completes, the output console is shown in the screenshots below and our website is deployed on the server :-

No alt text provided for this image
No alt text provided for this image

For every job, jenkins launched dynamic nodes as docker containers shown in screenshot below :-

No alt text provided for this image


No alt text provided for this image

Now if any update is pushed by developer, jenkins job will be automatically triggered by the Github webhook, it will build the new image and push it to the docker hub and trigger the next job, after that, the next job will check if the deployment is already created in Kubernetes, then it will rollout the update, till the time the existing clients are there, it will keep showing them the older version of website and as soon as all the traffic is sent to the new update, K8s will keep terminating the old pods and launch the new pods with the new update and it won't affect anything. Website is rolled out with zero downtime and no interruptions. The output screenshots of console and updated website are shown below :-

I have used kubectl get pods -w because I wanted to take live screenshots of pods older pods being terminated and new pods being launched but my slow system didn't allow that. You can still see it in status what I wanted to show.

No alt text provided for this image

Website after the Update is shown below :-

No alt text provided for this image

Some of the screenshots from build pipline view of both the jobs are also shown below :-

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

I hope you liked the basic demo of the Rolling Updates strategy used by the MNCs and Startups. Also, Feedbacks and Suggestions are always welcome.

要查看或添加评论,请登录

Pawan Kumar的更多文章

  • DevOps Automation using Groovy in Jenkins Job DSL

    DevOps Automation using Groovy in Jenkins Job DSL

    Whenever we talk about DevOps, it comprises of 2 words Dev + Ops meaning Developers sharing some load of the Operations…

    3 条评论
  • Integrating Prometheus & Grafana Keeping their Data Persistent in K8s

    Integrating Prometheus & Grafana Keeping their Data Persistent in K8s

    You must have always wondered about keeping the data of your monitoring system having prometheus and grafana running as…

    2 条评论
  • Automating Continuous Deployment in DevOps using Jenkins

    Automating Continuous Deployment in DevOps using Jenkins

    What are we going to build :- Create container image that has Jenkins installed using dockerfile. When we launch this…

    1 条评论
  • Creating a WebServer Infrastructure on AWS using Terraform

    Creating a WebServer Infrastructure on AWS using Terraform

    Few years ago, World started using cloud for their infrastructure as it saves a lot of their cost for the hardwares and…

    1 条评论
  • Automating CI/CD Pipeline in DevOps

    Automating CI/CD Pipeline in DevOps

    In this Article, We are going to Automate the Deployment and Monitoring of a Web App through the Jenkins running in…

    5 条评论
  • Creating a Basic Pipeline in DevOps

    Creating a Basic Pipeline in DevOps

    This is a Project based on the first 8 days of DevOps Assembly Lines training under our mentor Vimal Daga Sir and In…

    2 条评论
  • A big thanks to IIEC Rise

    A big thanks to IIEC Rise

    Finally completed the Docker project and this is my joomla cms running on the docker containers. Few days ago, I wasn't…

社区洞察

其他会员也浏览了