What is Kubernetes:
Kubernetes is an open-source tool used to manage and orchestrate the containers across the nodes/server, which helps us to build cloud-native applications released by google in 2014. All top 3 cloud providers support Kubernetes as serverless offerings.
Why we should adopt Kubernetes
In the world of microservices, managing the deployment and scaling of hundreds or thousands of APIs can be a daunting task. Each service is isolated and may have different requirements; for instance, using Java for authentication and authorization, Node.js for database interactions, and Python for machine learning operations. This diversity in runtimes and associated packages complicates management. Containers provide a solution by encapsulating these different environments, but managing a vast number of containers is still challenging. This is where our hero comes into play, efficiently managing container deployment, automatically scaling to handle sudden traffic spikes, and addressing issues like server failures and container crashes.
Below are a few use cases where we can think of Kubernetes.
- Large Scale application deployment
- Managing Microservices
- Enabling Serverless Computing
- Hybrid and Multi-Cloud Deployments
- Big Data Processing
- Computation
- Machine Learning
- MLOps
Core components of Kubernetes:
In this chapter, we will understand Kubernetes components at a very high level and we will go in-depth in our upcoming chapters
POD:
Is the place where Kubernetes will run our containers, a single POD can have one or more containers running. What is the speciality of POD? PODs are the wrapper of our containers with shared memory and network maintained by Kubernetes. A group of POD are called Kubernetes clusters.
Services:
Is used If we want to expose a service deployed in POD over the internet or if two PODs in Kubernetes clusters want to talk to each other
- External Service: for a web app or public APIs
- Node port
- Load balancer
- Internal Service: for Database
- Cluster IP
*we will have a dedicated session in Services.
Deployments:
It tells Kubernetes how POD can be deployed or modified once deployed mainly in terms of scaling and re-deploying the PODs, it is recommended for deployments for production.
Replication Controller:
It ensures that a given number of PPOD replicas are running all the time, will make sure all the PODs are running with no downtime by creating a new POD if any failure happens, Deployments are the new version of the Replication Controller. Which is not recommended to use, we can configure the replication in Deployments.
Config Map:
A typical properties file that stores information like filenames, folder names, URLs a few other configurations that may change from environment to environment. Our POD will have easy access to the config map so it helps to decouple the configuration artifacts. We can say config map is a typical configuration or a property file.
Secret:
Same as config Map but used to store credentials of the different applications with base64 encoded format or using any encryption techniques like SHA
Stateful Set:
Containers are meant for deploying stateless applications whenever we restart or redeploy the containers the data stored in the container will delete in order to make containers persistent we use stateful sets majorly used to manage the database as DB is a stateful
1. For example, if we want to have two replicas of DB and we will be using a single volume for both of the replicas, in that case, we will go for a stateful set
2. DB management is complicated to manage using K8, so it is preferred to host DB outside the K8 clusters
Volumes:
Containers are stateless to make it stateful we can use storage on the local machine or mounted storage volumes
- Ephemeral volume types have a lifetime of a pod.
- Persistent volumes exist beyond the lifetime of a pod
Replicaset:
It is a process which will make sure the number of POD replicas is running all the time by recreating a new POD in case of any failures of the existing POD, we can configure Replica sets in deployments.
Kubectl:
Is a command line configuration tool that helps to communicate to kubernetes clusters
with the help of Kubectl user can create, delete, update and inspect kubernetes services. As a developers we use CLI a lot in day to day life, we will discuss it in details in our upcoming lectures.
Kubernetes Architecture:
Kubernetes works in master and slave architecture. We will try to understand the different components and it’s roles in master and slave servers.
Master Node / Control plane:
Kube API- Server:
performs all the administrative tasks on the master node. A user sends the rest commands as YAML/JSON format to the API server, and then it processes and executes them. The Kube API-server is the front end of the Kubernetes control plane.
etcd
is a distributed key- Value store that is used to store the cluster state. Kubernetes stores the file in a database called the etcd. Besides storing the cluster state, etcd is also used to store the configuration details such as the subnets and the config maps.
Kube-scheduler
is used to schedule the work to different worker nodes. It also manages the new requests coming from the API Server and assigns them to healthy nodes.
Kube Controller
Manager task is to obtain the desired state from the API Server. If the desired state does not meet the current state of the object, then the corrective steps are taken by the control loop to bring the current state to the same as the desired state.
There are different types of control managers in Kubernetes architecture:
- Node Manager- it manages the nodes. It creates new nodes if any node is unavailable or destroyed.
- Replication Controller- it manages if the desired number of containers is running in the replication group.
- Endpoints controller- it populates the endpoints object that is, joins Services & Pods.
Worker node /data plane components:
Every worker machine has three main components installed as listed below
- Container run time
- High-level
- Low level
- Kubelet
- Kube proxy
Container runtime:
This is the software that is responsible for running containers. Kubernetes supports several container runtimes: Docker containers.
Initially, Kubernetes supports only Docker as a container runtime engine. But in recent times google announced Kubernetes is deprecating Docker, but no worries they are many container runtimes that Kubernetes now supports:
- Containerd (from Docker)
- Rkt (direct integration to be replaced with rktlet)
- Cri-O
- Frakti (Kubernetes on the hypervisor, previously Hypernetes)
- Rktlet (CRI implementation for rkt)
- cri-containerd
Kubelet:
Is an agent that runs on every worker node, it makes sure containers are running on POD based on the user command like create, delete and update
Kube Proxy:
Is a network proxy which runs on every node that is part of the Kubernetes service. It maintains network rules to allow communication to pods within the same node or different nodes either from inside or outside the cluster. It watches the API server for new Services and Endpoints.
Kube proxy supports the following services to achieve load balancing that redirects traffic to pods that match Kubernetes services
- User space
- Iptables
- ipvs
- Win user space