Kubernetes

What is Kubernetes? - Kubernetes is an open-source container orchestrator that automates the deployment, scaling and management of containerized applications. Containerized applications are applications that contain all the dependencies and runtime necessary to start the application successfully.

What Problem Does Kubernetes Solve?

  • 24/7 Application Availability - with a container orchestrator like Kubernetes, nodes or processes can be scheduled across machines, different times. This allows us to lose a node or a process without noticing any disruption in the uptime of our service.
  • Fault-tolerant and self-healing infrastructure - with Kubernetes If a process disrupts or the entire node goes down, a new process will be rescheduled by Kubernetes on a healthy node.
  • Efficient use of cloud resources - with Kubernetes Rather than having a single process running on a single cloud node that we pay for 24/7, we can schedule many processes on a single node. This node can also recognize when a new process cannot be scheduled and thus require new resources, and also when these resources are idle and need to be spun down.

Basic Architecture Of Kubernetes Cluster

WhatsApp Image 2022-01-18 at 12.02.53.jpeg

Kubernetes cluster’s most basic architecture has two major Nodes

  • Master Nodes
  • Worker Nodes

Worker Nodes - We will be looking at how the worker node work and the key component that makes up the worker node.

As a developer or a cloud Administrator any time we want to deploy our containerized app or autoscale it or we want to roll out any new update on our production-grade server, we often deal with the worker nodes.

This is the node that does the actual work required by the developer or cloud administrator. The worker node can contain one or more pods. These pods are the smallest unit of Kubernetes, which is an abstraction of a containerized application

Every worker node runs 3 key processes which are:

  • Container Runtime
  • Kubelet
  • Kube-proxy

Container Runtime - Every microservice we build is packaged into a single pod that has its own container runtime. We need to install a container runtime into each of the worker nodes so the pods can run there.

Some examples of container runtime:

  • Docker
  • Containerd

Kubelet - Now let’s talk about Kubelet, another process of the worker node. It is a primary agent that interacts with both the node and the container in a worker node.

The Kubelet is responsible for:

  • Running the pods containers.
  • Reporting the status of the node and each pod to the API Server.

Kube-proxy - Kubernetes cluster can have many worker nodes and each of the worker nodes can also have many pods which are running. So for one to access this pod they do so via Kube-proxy.

WhatsApp Image 2022-01-18 at 12.02.53 (1).jpeg

Master Nodes - the Master Node is responsible for managing the worker node efficiently. They interact with the worker node in order to :

  • start /restart pods
  • Monitor the worker nodes/pods
  • Manage the new worker nodes joining the cluster

Every master node runs these key processes which are:

  • Kube-apiserver
  • Kubectl: Kube-controller-manager
  • Kube-scheduler
  • etcd

Kube-apiserver - it is the main gateway for accessing Kubernetes clusters or it is the front end for the Kubernetes control plane(master node).

kube_apiserver.PNG Whenever we want to Deploy a new app, schedule any pods, or create any new service, we need to make a request to the API server of the master node, which then validates our request before we get access to the processes in worker nodes/pods.

Kube-scheduler - As a Kubernetes administrator or a developer every time we want to schedule a new pod on the worker node, we need to send the request to the master API server which in turn will make a call to the Kube-scheduler process. The Kube-scheduler will intelligently decide on which worker node this pod should be placed.

Therefore, Kube-scheduler can then be defined as: The key Control plane component keeps a watch for newly created Pods with no assigned worker node and selects a worker node for them to be scheduled and run on.

Kubectl: Kube-controller-manager - it is one of the important and critical processes in master nodes that monitors the status of any worker node level failures. It monitors events like the Crashing of any pods in the worker node and it then requests the scheduler to restart or reschedule any dead/failed pods after it has detected such an event.

etcd - etcd in the master node( control plane) is responsible for storing every kind of cluster-level change in the form of key-value pairs. It is seen as the brain of the Kubernetes cluster which keeps a log of every minute detail of changes occurring in the cluster.

For example, when a pod crashes in the worker node and it has to be rescheduled/restarted, the event gets stored in etcd as key-value pair, also the event of pod rescheduling on the node is also logged here.

Here is a diagram of the Kubernetes master node workflow

WhatsApp Image 2022-01-18 at 12.02.53 (2).jpeg