Kubernetes is one of the most popular and evolving technologies that helps in managing containerized workloads. I recently got the opportunity to be part of a Kubernetes workshop. In this blog I would like to share the learnings I acquired on Kubernetes architecture.
Kubernetes
- Kubernetes (also known as K8s -> K followed by 8 letters and a s ) is an open source software that is used for deploying, scaling and managing containerized applications.
- As a container orchestration system, it takes care of scheduling workloads across multiple containers, scaling in or out containers based on the demand or resource failure, and defining deployment patterns that ensures zero downtime of your containerized application.
Architecture
- The K8s architecture is a Classical Master-Worker architecture.
- When you deploy with K8s, you get a cluster. The K8s cluster contains one to many nodes. There are two types of nodes in the cluster - the master and the worker nodes. In the case of a single node cluster, the same node acts as the master and worker node.
- The master node is used for administrative tasks whilst the worker nodes helps to run your containerized applications.
The below architecture diagram depicts a K8s single master - multiple worker nodes cluster.
Let's understand every component one by one to understand it better.
As you can see, the container is the smallest unit. A Pod contains one or more containers. A Node contains one or more Pods. And a cluster contains one or more nodes.
Master node / Control plane
As the name suggests, this takes control of all the container activities. Starting from receiving requests, selecting the node to deploy the container, storing the information about the members of the cluster, monitoring the nodes, distributing the workload among nodes and handling availability of containers in case of node failure. In short it is the “Brain” of the cluster!
Master node consists of the following components which together accomplish the mentioned responsibilities.
API server
- It is the face of the master node that exposes the Kubernetes API.The REST requests to K8s will come through the API server.
- This takes care of authenticating and authorizing the request and modifying or retrieving the container data of the cluster.
Controller Manager
- This periodically compares the current state of the cluster with the desired state through the API server. In case of difference, it takes necessary actions to keep the states in sync.
- It also handles grouping of K8s objects (This groups services and pods (K8s components) by matching the labels)
Scheduler
- It continuously watches out for new Pod requests.
- It assigns worker nodes to spin up the requested Pods based on a few parameters like node availability, resources requested by the Pod, affinity, etc.
Etcd
- This is the only stateful component of the K8s cluster.
- It is a consistent and highly available key value store used to store all the cluster state and information.
- It is the source of truth in K8s architecture.
Worker node
This is also known as “Minion”. The worker node is where the Pods which run your containerized applications are monitored.
Kubelet
- This is an agent that runs on each node of the cluster.
- It is responsible for monitoring the containers running in a Pod.
- This keeps checking if there are any new Pod requests, ensures Pods are created with required containers (using container runtime) and reports back the current state to the master through API server.
Container runtime
- It is a software used for running containers.
- This acts as a container abstraction component. This is responsible for managing images, starting or stopping containers.
- This can be any OCI compliant container engine like Docker daemon, rkt (rocket) or containerd.
- Kubelet uses container runtime APIs to create or manage the containers.
Kube-proxy
- It deals with networking within the node.
- This is responsible for assigning IP addresses to each of the Pods with the help of Container Network Interface (CNI) provider.
- This also helps in keeping the IP tables updated and in resolving service (K8s component) abstractions.
Pods
- A Pod is a set of containers with shared storage, network resources, and a specification for how to run the containers.
- These containers running in a single Pod are relatively tightly coupled. In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to the containers running on a single Pod.
Kubectl
Given the architecture of K8s, in order to communicate with the cluster we would need whats called the Kubectl.
- Kubectl - Kubernetes command line interface is used to communicate with the K8s cluster.
- It offers a set of commands that can be used to create and manage K8s components. These commands interact over the RESTful API interface of the cluster’s API server.
Interaction between components
Within the cluster, any communication is orchestrated by the API server.
Say there is a request to start a new Pod.
-> The Kubectl command will reach API server as a request.
-> API server will store the request in etcd.
-> Control manager will detect the difference between the current state and desired state of the cluster stored in etcd.
-> On detecting the gap to be filled, Scheduler will identify the compatible worker node to start the new Pod and communicate the same to the API server.
-> API server will store this info into etcd and send the Pod creation request to the chosen worker node's Kubelet.
-> Kubelet will satisfy the Pod creation request by starting Pod with given container configuration using the container runtime in the cluster.
-> kube-proxy is used for networking needs like assigning new IP to the Pod. This updates the IP table rules and ensures Pod to Pod communication happens seamlessly.
And finally the new Pod is created.
Hope this gives a clear picture on how K8s works behind the screen and provides a base for exploring more and more of K8s :)
Happy learning!
Top comments (0)