Getting started with Kubernetes
After 5 years I had a proper vacation. But thanks to corona I couldn’t spend it travelling or having a drink with friends . So I decided to teach my self something and Kubernetes always looked interesting to me. With some external motivation as well I started checking what this is. This article is aimed for someone who wants to get into learning path of Kubernetes. I am NO k8s expert , I barely scratched the surface of it but really loved entire concept of k8s. So definitely I will be writing more articles around this topic.
As mentioned above I am going to structure this article the way I started doing my learning. I will explain what Kubernetes is , Main components , Architecture of K8s also I will setup K8s cluster using MicroK8s , deploy pods using yaml and so on. This is going to be a lengthy article as I will be touching upon all the related topics as well.
Virtualization ?
To simply put Virtualization is the process of creating software based / virtual version of something. This could be compute, storage, network , servers or application.
This concept use software to create an abstraction layer over physical hardware , that allows the hardware elements of a single computer such as CPU, Memory , Storage to be divided into multiple virtual computers. Each of these machines can behave independently even if they run using portion of actual underlying computer hardware.
If you want to dig deep into Virtualization. Here are some good resources to watch and read. (1 , 2)
Containers and Virtual Machines (VM)
In order to learn what K8s are and what it does , it’s very important that we understand the concept of Containerization. I figured best way to learn this would be compare this concept to Virtual machines and talk about the differentiation there.
Both Virtual Machine and Containers are different ways of achieving virtualization. VMs are called as Hardware Virtualizations. Because it happens in the hardware level as the name implies.
As shown in the image, base layer of VM is Hardware. On top of that we have a Hypervisor (HV). HV is what is responsible for creating these virtualized instances of the components that needs create a VM (CPU, Memory , Storage etc). In terms of Isolation , we get Isolation type of machines , As you can see we are using our single machine and creating multiple workstations (M1 , M2 , M3 ). Each of these machines are relatively independent from each other.
When it comes to containers we have Hardware in the bottom . Next we have have a Kernel , Kernel enables communication between hardware and software. On top of the kernel we have the operating system , often this is called Host OS as this is what will be hosting our containers. After the OS we have our containers , single machine can run many dozens on containers. Containers are Operation System level virtualization. In containers we are dealing with process Isolation. Think of application word and excel running on your machine , they are running in the same environment, These application can see what are the other processes running in this environment and interact with them. But when it comes to containers (C1, C2 etc), They are sharing the same operating system , same kernel but it appears to containers as if they are running their own operating system. And containers only have the libraries , scripts and code that are needed to run our deployed application. All these containers (C1, C2, C3) can run side by side , and they don’t necessarily have to know about each other. This is why this type is called process Isolation. Digging into little deeper , it’s important to know how these resources are accessed by the containers and how it is managed. So there are two features of Linux kernel , that are mainly used for this illusion of isolation . namespaces and cgroups (control groups). Namespaces takes care of the customization and make containers look like they have their own operating system. Cgroups are responsible for monitoring and restricting resources that are provided for the containers. Containers have infinite portability because we can define our container in a single file , this containers information such as how to build our container , how to run it , what libraries are necessary to have , actions to take on a crashed container etc. So if we want to replicate this containers in different environment we can just take this file and spin up our application.
Read more about namespaces (1 , 2) , cgroups (1)
What is Kubernetes
Previous section didn’t really cover anything about the Kubernetes, Reason why I wrote that section was , Those concepts helped me a lot to grasp basics of Kubernetes. In this section I will explain what is k8s , Why it is there , high level architecture of K8s and some basic concepts.
Lets start with the official Kubernetes definition from Google.
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. Kubernetes lets you run distributed systems resiliently with scaling and failover for your application.
Simply put , it is a container orchestrator tool , that helps to manage each container is where it’s supposed to be and those containers can interact with each other if necessary. Easier way to understand this concept would be to think of a conductor of a orchestra , he’s the one who tells that drums should go now , trumpets should stop , so that music will sound the way that composer wants. Just like a large orchestra , applications now a days have lot of granular components , thanks to the adopted micro services architectures. So k8s is the conductor responsible to make sure that application runs the way developer intends to. I will explain more about this in the below section.
Read more on Medium.
Keep up the good work Charith Wickramasinghe !!!