Continuous Deployment with Microservices using Kubernetes and Jenkins
What is a Microservices?
Before understanding Microservices, let’s discuss about Monolithic.
In a monolithic architecture, all code is in one principal executable file which can be tougher to troubleshoot, test and update.
Hence, we can deploy the code base of our system in a project and any updates in the system will be applied using a continuous integration (CI) pipeline can be adopted in a continuous deployment (CD) pipeline to deploy the system continuously into production environment. Under such circumstances, the CI or CD pipeline will execute every change introduced into the system. For instance, implementing an updating on the current system will require:
- 10 minutes of Unit Testing
- 2 hour Acceptance Testing
- 15-20 minutes deployment.
However, the deployment time may be significantly longer for larger systems.
Now, coming to Microservices, when we split a monolithic system into multiple microservices and deploy every service independently then every code change introduced to the system will only effect the individual service. Now, we just need to deploy the changed service and re-run CI or CD pipeline of the service. The total time taken for successful deployment is as listed below:
- 1 minute of Unit Testing
- 1 minute of Integration testing
- 5 minutes package
- 5 minutes deployment
After splitting, we can better meet the decoupling requirements by minimizing the required changes when a code change is introduced. However, since the services are split, major effort is necessary for independent deployment of every service.
In microservices scenarios, different services may adopt different technologies based on demands and each service requires its own CD pipeline. Therefore, creation of a new service necessitates frequent configuration of the supporting logs and monitoring systems, posing a huge challenge for CD.
What is Continuous Deployment?
Build and test your code automatically. If tests pass – make your application available for deployments, deploy it to a test environment and verify whether the deployment was a success or not. If the test deployment was a success, promote that code to production.
Let’s take an example of Web Application developed on Java Language using spring boot framework which splits into 3 Microservices:
Prerequisite for Continuous Deployment (CD) with Microservices using Kubernetes and Jenkins pipelines according to our use case: –
- Docker for Mac / Windows / Linux – This allows us to build, run and test Docker containers outside of Kubernetes on our local development machine.
- Cloud Account – Like on for AWS, Microsoft Azure
- Kubernetes – To deploy the containerize application.
- Cloud Instance – For setting Kubernetes environment.
- Public/Private Domain – Use services like AWS route53.
- A GitHub account, and Git installed locally – These code examples are stored on GitHub, by using Git locally you can fork the repository and commit changes to your own personal copy of the application.
- Docker Hub Account – If you would like to follow along with this tutorial, you’ll need a Docker Hub account in order to push and store your copies of the container images that we will build below in the image.
- Java 8 (or 9) SDK and Maven – We will be building code with the Maven build and dependency tool that uses Java8 features.
- Ambassador – L7 load balancing in kubernetes services. For Zero Downtime deployment.
- Jenkins – For Pipeline & Continuous Deployment.
To achieve continuous deployment according to our above Web Application example
Let’s say that when a Development Team make any changes in any of the services, it creates Jenkins pipeline to achieve continuous deployment end-to-end.
The Pipeline should like
Benefits of Using Continuous Deployment
- Users can fix, update, improvement new features in their hands early and often. The “patch” and upgrade cycles are integrated into daily usage, not spaced out in major releases.
- Internal Managers (Like Product owners for individual lines of business can do marketing campaigns, etc.) can see their projects decoupled from all the other projects in the organization, therefore they are ready to be presented to end customers immediately as soon as it is ready, not dependent on numerous other variables or “release trains.”
- Make deployments frictionless without compromising security.
- Scale from a single application to an Enterprise IT portfolio.
- Connect your existing tools and technologies (such as CI providers, DevOps tools, or scripts) into a harmonious workflow.
- Integrate teams and processes with a unified pipeline.
- Create workflows across the development, testing and production environments
- Provide a single view across all applications and environments.
- Ship both cloud-native and traditional applications into a unified pipeline.
- Improve overall productivity.
Setting up the continuous delivery pipeline and automating testing is extremely challenging in monolithic architectural styles. This is mainly because of dependencies. Services aren’t independent the entire logic is within the pipeline.
With microservices, software teams can test separate components and prevent risky deployments. In microservice architecture, the entire logic is transferred from the pipeline to endpoints making services independent. Moreover, without microservices – a lot of dependencies have to be met to prepare various environments for testing. The microservice architecture enables development teams to set up these environments quickly, deploy fast and automate the complete cycle.
Microservices improve the traditional delivery approach and ships release specific to services and components making the entire release safe, cost-effective and quick to debug.
Kubernetes help to deploy docker containerize application that can be scalable, Load Balanced, maintained in the docker networking and blue/green (B/G) deployment strategy that will deploy the build on production without any downtime can also give one of the major benefit that it can follow a canary workflow which helps to route the customer to use the latest deployed application.
Microservice architecture has resolved this complexity and helped many product companies to build loosely coupled services that could be changed, scaled and easily managed. With the entire application divided in various small set of services, each running on its own but communicating with each other through APIs – understanding application becomes a lot easier.
It also enable DevOps and helps companies to focus on zero-downtime, continuous integration and deployment. With so many benefits, microservices are gaining traction and here to stay for long.
Author : Rishabh Gupta