Deep Dive into Kubernetes Architecture
Tags: kubernetes, containers, docker
Published: 2024-06-24 17:59:30

Hello everyone, welcome back to my blog series on CKA 2024 in this fifth entry of the series, we'll be diving deep into Kubernetes architecture, focusing on the control plane components, their roles, and how they work. If you're new to containers and Kubernetes, I highly recommend reading the previous posts first. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijuo1b8kv80jg57akpkf.jpeg)

## Understanding Kubernetes Architecture
Kubernetes architecture can seem overwhelming at first glance, but by the end of this post, you should clearly understand its components and their functions. The architecture is divided into two main parts: the control plane and the worker nodes.

### What is a Node?
In Kubernetes, a node is essentially a virtual machine (VM) that runs your components, workloads, and administrative functions. Nodes are categorized into control plane nodes and worker nodes.

#### Control Plane

The control plane or master node is like the board of directors in a company. It provides instructions and management but doesn’t perform the actual work. It hosts several critical components:

1. **API Server**: All operations on the cluster are executed via the API server. It handles RESTful calls, validates them, and processes them. Only the API server communicates with etcd to store and retrieve cluster state and configuration.

2. **Scheduler**: The scheduler assigns pods to nodes based on resource availability and other defined policies. It continuously monitors the API server for new pods without a node assignment and allocates resources accordingly.

3. **Controller Manager**: The controller manager runs various controllers in Kubernetes. Controllers are responsible for noticing and responding when the actual state deviates from the desired state.

4. **etcd**: etcd is a consistent and highly-available key-value store used as Kubernetes’ backing store for all cluster data. It stores configuration data, secrets, and the state of all resources in the cluster. Only the API server interacts directly with etcd.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyockdxuufuvlsukagpw.png)

#### Worker Nodes
Worker nodes are where the actual work happens. They run your applications and workloads encapsulated in pods. Each worker node contains the following components:

1. **Kubelet**: An agent that ensures the containers are running in a pod. It receives instructions from the API server and manages the pods' lifecycle.

2. **Kube-proxy**: Manages network rules on each node. It allows for network communication to your pods from network sessions inside or outside of your cluster.

3. **Pods**: The smallest deployable units that can be created, managed, and run in Kubernetes. Each pod encapsulates one or more containers.

### How Control Plane Components Work Together
To better understand how these components work together, let's walk through an example of scheduling a pod:

- **User Request**: A user or DevOps engineer uses kubectl, a command-line tool, to request the creation of a pod.
- **API Server**: The request is sent to the API server, which authenticates and validates it.
- **etcd Update**: The API server updates the etcd store with the new pod configuration.
- **Scheduler**: The scheduler detects the new pod and assigns it to a suitable node based on resource availability.
- **Kubelet**: The kubelet on the assigned node receives the pod specification from the API server and ensures the container(s) are running.
- **Status Update**: The kubelet reports the status back to the API server, which updates the etcd store with the current state.
This process ensures that workloads are efficiently scheduled and managed across the cluster.


### Conclusion
Understanding Kubernetes architecture and its components is crucial for managing and scaling your applications effectively. The control plane components like the API server, scheduler, controller manager, etcd, work in unison to manage the cluster state, while worker nodes run the actual applications.

If you have any questions or need further clarification, feel free to leave a comment. Stay tuned for the next entry in our CKA 2024 series!

For further reference, check out the detailed YouTube video here: 
{% embed https://www.youtube.com/watch?v=SGGkUCctL4I&list=WL&index=19 %}