# Day 21 - Kubernetes Architecture

## 🧩 1. Why “K8s”?

* The word **“Kubernetes”** has **10 letters**.
    
* To shorten it, the middle 8 letters (“ubernete”) are replaced with the number **8**, forming **K8s**.
    

> Kubernetes → K + 8 letters + s → **K8s**

---

## 🐳 2. Docker vs Kubernetes (Before Architecture)

Before understanding Kubernetes architecture, you must know how it differs from Docker.

| Feature | Docker | Kubernetes |
| --- | --- | --- |
| Nature | Single host container platform | Cluster-based orchestration platform |
| Self-healing | Manual restart needed | Auto-healing built-in |
| Scaling | Manual | Auto-scaling |
| Load balancing | Basic | Advanced load balancing |
| Enterprise support | Limited | Strong networking, security, scheduling, and monitoring |

👉 Hence, **Kubernetes = Enterprise-level orchestration** of containers across clusters.

---

## 🏗️ 3. Basic Idea

Kubernetes architecture has two main layers:

```plaintext
+----------------------------------------+
|        Kubernetes Architecture         |
|----------------------------------------|
| Control Plane (Master Components)      |
| Data Plane (Worker Node Components)    |
+----------------------------------------+
```

---

## ⚙️ 4. Core Concepts: Container vs Pod

* **In Docker:** smallest unit = **Container**
    
* **In Kubernetes:** smallest unit = **Pod**
    

A **Pod** is like a wrapper around one or more containers — with added features like networking, restart policies, and scaling.

---

## 🧱 5. Kubernetes Node Structure

### Kubernetes Cluster =

* 1 or more **Master Nodes** (Control Plane)
    
* 1 or more **Worker Nodes** (Data Plane)
    

For simplicity:

```plaintext
1 Master Node + 1 Worker Node
```

---

## 🧮 6. Data Plane (Worker Node) Components

Each **Worker Node** contains components responsible for **running the actual application Pods**.

### 🧩 Components:

1. **Kubelet**
    
    * Ensures Pods are running as expected.
        
    * Talks to the Control Plane.
        
    * Reports pod status.
        
    * Performs “auto-healing”: restarts pods if they crash.
        
2. **Kube-proxy**
    
    * Manages **networking and communication** between Pods and nodes.
        
    * Allocates **IP addresses** to Pods.
        
    * Handles **service load balancing**.
        
    * Uses Linux **iptables** for routing.
        
3. **Container Runtime**
    
    * Actually runs containers inside Pods.
        
    * Examples:
        
        * Docker Shim
            
        * containerd
            
        * CRI-O
            
    * Kubernetes supports any runtime that implements the **Container Runtime Interface (CRI)**.
        

> **Summary:**  
> Worker node = { Kubelet + Kube-proxy + Container Runtime }  
> → These three together form the **Data Plane**.

---

## 🧠 7. Control Plane (Master Node) Components

These components **control, schedule, and manage** the cluster.

### 🧩 Components:

1. **API Server**
    
    * The **heart of Kubernetes**.
        
    * All external or internal requests go through it.
        
    * Provides the Kubernetes REST API.
        
    * Validates and processes commands (e.g., from `kubectl`).
        
2. **Scheduler**
    
    * Decides **which node** should run a new Pod.
        
    * Uses resource data and rules to make the placement decision.
        
3. **etcd**
    
    * The **database of Kubernetes**.
        
    * A **key-value store** that saves cluster state and configuration.
        
    * Used for backup and recovery.
        
4. **Controller Manager**
    
    * Runs background “controller” processes that manage the cluster state.
        
    * Examples:
        
        * **ReplicaSet Controller** → ensures correct number of pods.
            
        * **Node Controller**, **Endpoint Controller**, etc.
            
    * Ensures the cluster stays in the **desired state**.
        
5. **Cloud Controller Manager (CCM)**
    
    * Bridges Kubernetes with **cloud providers** (AWS, Azure, GCP, etc.).
        
    * Handles:
        
        * Cloud load balancers
            
        * Cloud storage
            
        * Node management
            
    * Not required for **on-premises clusters**.
        
    * Open source – cloud vendors can extend it for their own integrations.
        

---

## 🔁 8. Flow Example — Pod Creation

1. **User runs command:**  
    `kubectl apply -f pod.yaml`
    
2. **API Server:** receives the request.
    
3. **Scheduler:** decides on which node to place the pod.
    
4. **etcd:** stores pod info and cluster state.
    
5. **Kubelet (on worker):** runs the pod using container runtime.
    
6. **Kube-proxy:** assigns IP, configures networking, enables load balancing.
    
7. **Controller Manager:** ensures the desired number of pods are running.
    

---

## 🧩 9. Summary Table

| Plane | Component | Role |
| --- | --- | --- |
| **Control Plane (Master)** | API Server | Entry point; handles all requests |
|  | Scheduler | Decides which node runs the pod |
|  | etcd | Cluster data store |
|  | Controller Manager | Ensures desired state (e.g., replicas) |
|  | Cloud Controller Manager | Integrates with cloud providers |
| **Data Plane (Worker)** | Kubelet | Runs pods, reports status |
|  | Kube-proxy | Manages networking & load balancing |
|  | Container Runtime | Runs containers (Docker, containerd, CRI-O) |

---

## 🧭 10. Final Concept

* **Control Plane** → “Brain” (decides, schedules, manages)
    
* **Data Plane** → “Body” (executes, runs workloads)
    
* Together they make Kubernetes a **self-healing, auto-scaling, cluster-based orchestration system.**
    

---

## 📝 11. Assignment Idea (Optional)

* Draw your own Kubernetes architecture diagram.
    
* Label control plane and worker components.
    
* Write a short explanation and post it on LinkedIn or GitHub as a study note.
    

---

✅ **In short:**

> **Kubernetes = Control Plane (manages) + Data Plane (executes)**  
> Each component has a clear, defined responsibility that together make K8s scalable, reliable, and automated.
