Kubernetes
gurunadh
Posted on August 10, 2024
Kubernetes is an open-source container orchestrator. To know about container orchestration and orchestrators visit Container Orchestration.
Kubernetes is sometimes shortened to k8s, as there are 8 characters between K and S.
History
Kubernetes originated from a Greek word κυβερνήτης (kubernḗtēs), meaning 'helmsman' or 'ship pilot'. As the name suggests, Kubernetes acts as the pilot on the ship of containers.
Kubernetes was originally developed by Google as part of their Borg System (Cluster Manager) and was later donated it to Cloud Native Computing Foundation (CNCF).
Features
Automated Rollouts and Rollbacks
Kubernetes progressively rolls out changes to your application or its configuration, while monitoring application health to ensure it doesn't kill all your instances at the same time. If something goes wrong, Kubernetes will roll back the change for you.
Service Discovery and Load Balancing
No need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.
Storage Orchestration
Automatically mount the storage system of your choice, whether from local storage, a public cloud provider, or a network storage system such as iSCSI or NFS.
Self Healing
Restarts containers that fail, replaces and reschedules containers when nodes die, kills containers that don't respond to user-defined health check, and doesn't advertise them to clients until they are ready to serve.
Secret and Configuration Management
Deploy and update Secrets and application configuration without rebuilding your image and without exposing Secrets in your stack configuration.
Automatic Bin Packing
Automatically places containers based on their resource requirements and other constraints, while not sacrificing availability.
Batch Execution
In addition to services, Kubernetes can manage your batch and CI workloads, replacing containers that fail, if desired.
Horizontal Scaling
Scale your application up and down with a simple command, with a UI, or automatically based on CPU usage.
IPV4/IPV6 dual stack
Supports both IPv4 and IPv6 addresses.
Portability
Kubernetes can be deployed in many environments such as local, remote VMs, in public/private/hybrid clouds.
Architecture
Kubernetes' architecture consists of
- Control Plane Node
- Worker Node
Worker Node & Components
Worker nodes provide a runtime environment for applications deployed in the cluster. Applications will be deployed only in the worker node, not in control plane node.
In multi-worker cluster traffic, between client and application deployed in Pods is handled directly by the worker node and is not routed through the control plane node. Each node can have multiple Pods in it.
Worker nodes must have three components.
Container Runtime
Although Kubernetes is a container orchestrator, it cannot run the containers directly. In order to manage container's lifecycle, Kubernetes needs a container runtime on both the worker node and control plane node.
Popular runtime tools in Kubernetes
- CRI-O - A lightweight container runtime for k8s.
- containerd - A simple robust and portable container runtime.
- Docker engine - Earlier it was the default runtime but deprecated in kubernetes version 1.20
Kubelet
Kubelet takes a set of PodSpec (simple yaml object that describes pod specifications) primarily from API server and is responsible to create the pod, assigns resource to the container from the node and manage containers lifecycle in the pod by interacting with the container runtime.
Kube-proxy
Kube proxy handles communication to and from pods that are part of a service within the cluster.
It forwards the requests between pods in an efficient manner and with low overhead.
Control Plane Node & Components
The control plane's components make global decisions about the cluster as well as detecting and responding to cluster events like starting up a new pod when Deployment replica's field is unsatisfied.
There are 4 main components in control plane
API Server
API Server acts as a cluster gateway also acts as gatekeeper for authentication of the Kubernetes. It is a critical component in Kubernetes that manages all the communication in the cluster.
We can run multiple api-server to balance the traffic.
Scheduler
When there is a request from client to schedule a pod, API server sends request to Scheduler to start the pod in one of the worker nodes. Scheduler is smart enough to choose a node that meets the pod requirements like ram, cpu, and least busy node with the required specification will be chosen to create the pod.
Scheduler just decides on which node a pod should be scheduled, while kubelet is responsible to create the pod.
etcd
It is the cluster brain, a consistent and highly-available key value store used as Kubernetes' backing store for all cluster data and not applications' data deployed in the cluster.
Every change in the cluster, when a new Pod gets scheduled, when a Pod dies, application deployment state, cluster health — all these changes will be stored as key-value store in etcd.
New data is written to the data store only by appending, data is never replaced, but obsolete data is deleted periodically to minimize size of the data store.
Controller Manager
Controller manager detects the cluster state change, when a pod dies in any node, the controller manager creates a new pod object and sends a request to the API server to create a pod with a desired state which will then send a request to the scheduler.
Kubernetes doesn't guarantee that the replacement for an existing pod will be scheduled to the same node as the old pod that was being replaced.
Posted on August 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.