Kubernetes is changing the landscape of how the applications are deployed, maintained and monitored. And it does so by saving a lot of infrastructure costs.
Today we will try and understand:
- Why you need Kubernetes?
- And you will eventually understand What Kubernetes is?
Why you need Kubernetes?
In order to understand this we need to look into how the application were developed before the introduction of Kuberenetes.
Before the Kuberenetes( which manages Microservices) was introduced to the IT industry, the applications were created as a monolith. All the components of an application, say front-end, back-end services were all tightly coupled as a single block. This made it very difficult to change the technology stack of the application.
A large application was broken down into smaller pieces with the introduction of Microservices. And each piece would communicate with each other over network calls; it became easier to replace any component of the application with any new technology/service.
Monolithic Applications vs Microservices Architecture.
Scenario : Assume your application consisted of the following components:
- Front end UI – written in Angular JS
- Service to maintain user accounts
- A service that allow users to browse through the product catalog
- Another service to maintain the inventory – which keeps track of the product availability
- Service for billing and shipping.
Now one approach would be to keep all these services in one single big monolith server.
Mentioned below are the Benefit of monolith apps:
- Easy to get started: How to separate out these services? you do not have to put a lot of thought on it.
- Easy to maintain – Since everything is grouped together it becomes easy to maintain the application. You just have to take care of one server and not all the services.
- Reduced Network I/O – Since all the components of the application reside in a single server, the communication response time between each of the component is high as there are no network calls made.
Caveats of monolithic architecture:
- Hard to switch technology stack – If you wanted to change your front-end from Angular to React, it would not be easy as all the other services will go down when you try to change just the UI and you don’t know if these services will be up and running when you start the server again.
- Improper resource utilisation – Let’s say you have 8GB of ram in you server. Assume that only your inventory system service needed 4GB of RAM. And 1 GB RAM for each of the other 4 services(and all these services under utilise the 1GB capacity). Now, if inventory needed 1 more GB of Memory, you would just have to scale out to the whole new server just for one service while other services were perfectly working fine.
Wouldn’t it be better if we can just allocate the amount of memory needed for each of the service. Well this is where Microservices come in to picture.
In Microservices, you separate out each of the components into smaller servers and scale only the services which needs extra resource and not all the servers.
Benefits of Microservices architecture:
- Separation of concern – separate out each of the components into smaller servers so that there is no tight coupling between the components.
- Easily switch the technology stack – if you wanted to update from Angular to React JS framework, you would just need to bring one of the services down and replace, all your other services would continue to be operational. So you don’t need to worry about what if the other service doesn’t restart and such other things which you would worry about in monolith.
- Efficient utilisation of the resources – The whole purpose of Microservices is the efficient utilization of the resources within a server and that is where docker helps.
Using Docker you can break down one big Server into multiple small servers called containers. So all your services would still be in one server(In AWS, GCP or on premise) but they are logically separated out from each other. So you could have 3 docker container for fronted UI, 3 for for inventory, 2 for user accounts, 2 for browsing catalogs and 3 for billing capacity.
This is how your server would look like when it is broken down into small containers. And let’s say there was not one server, there were three servers like these.
Problems after breaking the apps into smaller components:
The biggest problem with the Microservices is the management of all the smaller services.
- If the Docker container for angular are in different servers then how they will communicate/network with each other?
- How will you be able to monitor the traffic moving in and out of each of the container?
- Will one Angular docker container know that a new container has just spin up to load balance and distribute the traffic?
- How it will be made sure that traffic of different services will not cross connect with other services, hence security is not compromised?
So we need something which manages all the Microservices for us – and the answer to the above problems is Kubernetes.
What is Kubernetes?
Kubernetes manages the Microservices by providing a platform for their communication with each other, security, discovery of services running in same/another node and hence acts as an Orchestrator.
So when you create a cluster with Kubernetes installed in it, it creates one Master Node and one or more worker nodes. Master keeps track of all the activities within the cluster.
Following are the components of Kubernetes which helps in Microservices management:
API server – which maintains the communication between Mater and node Controller – which controls the replication of containers. Scheduler – Decides on which the new pods(Pod holds the containers – the word is taken from pea pod) should be placed.
ETCD : it keeps track of all the information needed by the Kuberenetes.
Kubelet – Is an agent which runs in each node, gathering the information about each of the pods running in it, how much traffic is going into each of the pods and things like that.
Service – It has the concept of Service which helps in Identifying the pods across nodes.
So it is with the help of its components, Kubernetes orchestrates the Microservices running in the servers and overcomes the complexities posed by Microservies architecture.
To understand the Kubernetes and its component in detail, there is no better place then its official website.