Kubernetes explained with car assembly

Kubernetes explained with car assembly

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 lines. 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 auto-scaling purposes, we wanted to keep it simple because the application itself was very simple. 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 containerize 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 of Kubernetes are that it is open source, supported by many public cloud providers, and has declarative files to deploy an application. It is already used by many companies managing thousands 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, this post intends to answer the questions that might arise in your mind when you hear `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 we would allocate the land for different departments like the main Production line, Paint shop, Washing area, Test drive lane, and Ground to park vehicles. Some of these things can be in a single production line.

I’m more interested particularly in the Production line because the problem we have is to utilize the space we have and the human resources we have to get maximum output. What we can do here is we can divide the total number of tasks by the 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 that 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 engines that can fulfill the need of the main assembly line.

Now, Let’s think in the context of Kubernetes. As in our car assembly, we have to utilize 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 in a way that is most efficiently utilized.

In the case of car assembly, it is the crane that moves forward the cars in the line. In kubernetes, it is the master node that will manage the cluster and maintains the state as defined in the kubernetes configuration file.

As we separated the car engine assembly into a separate production line, in containers we can separate some functionality from the main application and make a new service that 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 are 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 a similar kind of space we can replicate our previous plan without any effort. Same in kubernetes we can clone the environment for staging, testing purposes or to run the application on some other region available to serve users more efficiently.

Another advantage of kubernetes is that it has standardized most of the process using concepts like services, pods, replica sets, config map, and an ingress controller. It has become very easy for developers to grasp these concepts and not care about the underlying details.


How kubernetes can make my deployments easy?

If we are using AWS or GKE, we are dealing with clusters that can scale infinitely. We can allocate memory and CPU as much as we need, and we are only paying for what we are using. The tricky part is we can create these resources, but we don’t want to manage them manually by ourselves. We want to focus more on our application services than to manage bare-metal servers.

Let me explain how this makes our deployment process easy. In kubernetes, we get virtually unlimited memory and CPU to run our services and which is defined in the .yml file. So, we can deploy our new version without taking down the old version. Later, we can forward traffic to the new deployment, or we can increase the traffic to the new deployment as we get confidence in the latest deployment.

As I said before kubernetes has standardized the process. Kubernetes provides a way to define services in the declarative file. It is nice to have a standardized file. It is self-documented so other developers can also understand the process.


What does the cluster mean?

A cluster is a set of computers where you can deploy your services. Cluster made of actual VM machines but it provides you abstraction. Cluster is defined as the total CPU and total memory you have to deploy services. Suppose we have three VM machines each one has two cores and 4 GB of memory. So, We can say that we made a cluster that has 6 cores and 12 GB of memory. So when we deploy the service we don’t have to tell which machine it should use to deploy our service. We only have to define how much memory and CPU it will need. kubernetes will manage everything after that.


What is different from other cloud orchestrators?

Kubernetes is complete in the job it is supposed to do. It works on every cloud infrastructure whether it’s public cloud or in-house machines. So, It will be easy for you if in case you have to migrate to another platform. Kubernetes can work with any containers which have confirmed OCI standards. Kubernetes is great for micro-services architecture where the application is divided into parts, each has its database and communicates with each other with APIs because it provides isolation with the concept of namespaces. It provides various ways to deploy an application without any downtime. It has declarative files for deployment. So it provides clarity for other developers.


Related Posts

AWS Well-architected framework - points to be noted

AWS Well-architected framework - points to be noted

Introduction I’m passionate about learning different frameworks for creating checklists. These checklists can help you make cost-effective, resilient, and secure infrastructure.

Read More
How do I setup my dev box ?

How do I setup my dev box ?

Hey, This blog post serves as a guide to how I set up my MacBook and the tools I rely on.

Read More
Setting up a Microk8s cluster with a domain and SSL certificate

Setting up a Microk8s cluster with a domain and SSL certificate

Microk8s is a lightweight Kubernetes distribution that’s perfect for development, testing, and small-scale deployments.

Read More