Hola, I know for sure that the title might seem a little strange to you. Maybe you are thinking about what is the possible connection between kubernetes and car assembly line. Stay with me, it will all make sense. The only goal of this blog post is to answer the question “Kubernetes, What is it?”.
Well, I’m explaining kubernetes in laymen’s terms here.(or at least a story like blog to help you understand kubernetes).
It’s been a year since we put a containerized (Docker) application in production. When we started using containers for the auto-scaling purpose, we wanted to keep it simple because the application itself was very simple in its nature. So, we used the AWS Elastic Beanstalk platform to deploy our application. It was a great experience. If you have a very simple application, it is a great platform to deploy your application. You don’t need to go through the learning curve of container orchestration technologies. It is very rich in terms of functionality it provides.
But we soon realized and understood the advantages of using containers. As humans, we always strive for better. Greedy humans!. We decided to containerizing the projects that are already running in production. It didn’t take too long to realize that with the number of services we are running in some of our projects, Elastic Beanstalk is not the right tool for other applications because it does not provide anything to deploy & scale each service independently.
So, we explored what other options are available. We chose Kubernetes from the list. The advantages with Kubernetes are that it is open source, supported by many public cloud providers, has declarative files to deploy an application. It is already used by many companies managing thousand of nodes. So, it gives you a sense of confidence when you choose kubernetes as a cloud orchestrator. Kubernetes has concepts of pods, services, deployments, and abstraction that it provides to manage instances, which is just amazing! Well, the intention of this post is to answers the questions that might arise in your mind when you hear the `Kubernetes` for the first time.
Why do we need to use Kubernetes?
I’m assuming that maybe you are already familiar with any one of the container technologies out there like Docker, RKT, LXD and many others. If you’re a newbie to this, the following is just a gist of it.
Essentially, a container is a lightweight, virtualized, portable, software-defined environment in which software can run in isolation from other software running on the same physical host machine. Software that runs inside the container has only one purpose. In simple terms, a container is a packaged application with OS and libraries already installed. So, we can run it on any platform. It can behave like immutable component for infrastructure. So, it becomes very cheap to destroy it and run it whenever and wherever we need.
If you want to know more about containers read this post and come back.
What is it?
To visualize it better, imagine that you have allocated the land to build a car factory. What would you do? If you’re a fan of “Mega Factories” show just like me. you can do it. Well, this could be miles away in terms of reality but let’s give it a try. The first thing we will do is that we would allocate the land for different departments like the main Production line, Paint shop, Washing area, Test drive lane, Ground to park vehicles. Some of these things can be in a single production line.
I’m more interested particularly into the Production line because the problem we have is to utilize the space we have and human resource we have to get maximum output. What we can do here is that we can divide the total numbers of tasks by human resources we have. We can divide space into sections, and we can allocate the same time for each of the sections. We will create teams which will finish their assigned task at the same time so that we can move forward on the production line and no one has to wait and waste their time.
To make it more efficient, we can also assemble some parts on another production line. For example, a car engine. The only constraint is that we have to make enough number of the engines which are able to fulfil the need in the main assembly line.
Now, Let’s think in the context of Kubernetes. As in our car assembly, we have to utilize the time and space, in kubernetes, we want to utilize the memory space and CPU as efficiently as possible. Kubernetes has a set of machines where it can deploy our containers. This set of machines is called a Kubernetes Cluster. Now, we have X amount of CPU and Y amount of memory across the cluster. So when we spin-up containers in these clusters, it will run it in a way that it is most efficiently utilized.
In case of car assembly, it is the crane which moves forward the cars in the line. In kubernetes, it is the master node which will manage the cluster and maintains the state as defined in the kubernetes configuration file.
As we separated the car engine assembly to a separate production line, in containers we can separate out some functionality from the main application and make a new service which serves the purpose. So, it can be an independent component and can be managed by another team. Each service can communicate with each other through APIs. It is called a Micro-services architecture and with Kubernetes it makes the process pretty simple. We just need to define the service in a configuration file, with the maximum CPU & Memory it may utilize, and Kubernetes will handle the rest by itself.
In car assembly, if one team is less efficient in the task they are assigned to, we can always change the members or add new ones. Same with kubernetes, if it finds the health status of a service container is not healthy, it will replace the container by launching a new container. It is also called self-healing, which is very important when we have enough number of services.
In car assembly, one of the ways to scale is to increase the space and hire a few more workers. So, we can decrease the workload on each team, and we can increase the output. Same way in kubernetes, we can increase the number of containers in the cluster. If all the resources are utilized and more is needed, we can define processes to launch new containers and add them to the cluster automatically.
Now, think about the case where we get new land in some other place, and we want to make a new factory. So if we somehow get similar kind of space we can totally replicate our previous plan without any efforts. Same in kubernetes we can clone the environment for staging, testing purpose or to run the application on some other region available to serve users more efficiently.
Another advantage with kubernetes is that it has standardized most of the process using concepts like services, pods, replica sets, config map, ingress controller. It has become very easy for developers to grasp these concepts and not care about the underlying details.
Also Read: Enabling HTTPS for a Web Application on Elastic Beanstalk without Load Balancer