If you have just begun your journey in Google Cloud and are wondering what Kubernetes may be, this blog is just for you. When I learnt about various GCP services, Kubernetes was an area that I took a while to understand. Now let us start with the definition
“Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management.”
If we break it down, it is a service that helps us to deploy our code easily. Well what does the term “deployment” mean? It means we are making our code ready to be used by the intended audience.
One way through which deployment can be achieved is by using virtual machines; you request your service provider for a virtual machine of specific type where your code can run, and then deploy your code there. You can control how much memory is used, what kind of operating system the code is run on, and so on. This can be achieved through Compute Engine in GCP which is an IaaS component. But the drawback with this deployment method is that its flexibility comes with a cost. Assume you initially use 1 VM for deployment of a website, that can handle ‘x’ requests. But what happens when ‘2x’ visitors come to your website. How will this sudden intake be handled? If you decide to use another VM, what happens when the number of requests slides back to ‘x’? It will also take a lot of time for the VM to start, just like how your system might take a lot of time to boot up.
The second method will be for you to use a PaaS offering, such as App Engine. Here, you do not get a blank VM to deploy your code unlike the previous example; instead you get access to a family of services that your application might need. You just write your code and provide the related dependencies. App engine takes care of the deployment. Remember the problem we faced with Compute Engine where we had to decide how to handle ‘x’ and ‘2x’ number of requests? Well, you no longer have to think about that because scaling happens automatically. Cool right? But you have no say on the underlying architecture; you cannot decide what OS to use or how much memory to use.
This is where the hero of this blog enters: Kubernetes!! Kubernetes provides an intermediate ground for deployment. It uses the concepts of containers, pods, nodes, etc to achieve that easy deployment. But what do all these fancy tech terms mean? Let us go through them one by one :
Kubernetes : A quick glimpse
Node : It represents a computing instance. From GCP perspective, it is a virtual machine. We need a machine to run our code right?
Container : If you take a VM or your own personal machine, everything is bound to the OS right? The code, dependencies, libraries are all bound to the OS image. Now what is an OS image? It is like a copy of the OS. This statement might make it easy for you to understand the concept of an image : “When production computers are built, a preinstalled OS image is copied onto the hard drive rather than spending 2 hours on installing the OS, drives, files, etc.” In essence, it is just a file. Now a container does not contain this file, which makes it light weight. So a container is also a type of virtual machine which contains code, library and everything else except the OS image. This feature is what makes containers portable.
If you had to move a virtual machine around or create a copy of its content in another machine, you will have to install the OS image onto the new VM, which will take a lot of time to get installed and then the new VM has to boot up like a normal machine, which is again time consuming. Now imagine a VM that does not require this OS image to be copied and installed, which is what a container does. So moving a container image around is much faster, which implies it helps with scaling. Remember the ‘x’ vs ‘2x’ example? Now with a container, you do not have to wait until a new VM is created from scratch. You do not have wait until the system boots up. So it becomes easy to create copies of the container rapidly on demand. You just need an operating system that supports containers
With VMs, you do not have to worry about the hardware. Similarly, for containers, you not have to worry about the hardware as well as the operating system. So you can move your code from development, to staging, to production, or from your laptop to the Cloud without changing or rebuilding anything. You can create multiple containers, each performing a different function, just like how different machines perform different functions, and all these containers can coordinate with each other; they can perform the same task, or perform different ones.
Kubernetes is an orchestration tool. It coordinates different containers and manages how these containers use underlying resources.
Pods : Heard of a pea pod? It safely contains peas in it. Similarly, a pod in Kubernetes is a set of containers that are currently running.
Cluster : A cluster in Kubernetes is a set of nodes on which the containers are run. Each cluster has at least one node.
This might have given you a basic idea on what Kubernetes is and why it is used. In the second part of this blog, we shall discuss about Kubernetes in more detail.