Featured Image
Software Development

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 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


How kubernetes can make my deployments easy?

If we are using AWS or GKE, we are dealing with clusters that have the capacity to 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 it 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 new deployment, or we can increase the traffic to new deployment as we get confidence in the latest deployment.

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


How will help me to fully utilize my infrastructure and reduce the cost of my infrastructure?

Think about the plane of car assembly we made. Last time we increase the production by creating more teams and creating less burden on each team. We also replicated the production line on the new land we bought. Think about the scenario if we have to decrease the production number, what we will do is we will transfer workers to some other plants or some other work(I’m being positive here otherwise you know what will happen). Same in kubernetes we can scale down the services we don’t need. Which will automatically scale down the instances we have.


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 defined as total CPU and total memory you have to deploy services. Suppose we have three VM machines each one has two cores and 4 GB memory. So, We can say that we made a cluster which 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 a job it supposed to do. It works on every cloud infrastructure whether its 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 to OCI standards. Kubernetes is great for micro-services architecture where the application is divided into parts, each has its own database and communicate 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 clear for other developers.

Also Read: Implementing Cache Busting for Angular App Deployment on AWS S3 and CloudFront

author
Aniket Patel