๐Kubernetes Architecture๐
๐ Master Node Components in Kubernetes (K8s) โ Explained in Detail
In Kubernetes (K8s), the Master Node is the brain ๐ง of the cluster. It controls and manages worker nodes and ensures applications run as expected. The master node consists of several key components that work together for scheduling, state management, and cluster control.
๐น 1. Overview of Master Node Components
The Master Node contains these main components:
API Server (
kube-apiserver
) โ The front-end and gateway of Kubernetes.Controller Manager (
kube-controller-manager
) โ Manages controllers that handle cluster operations.Scheduler (
kube-scheduler
) โ Decides which node runs which Pod.Etcd โ The key-value store that holds cluster data.
Cloud Controller Manager (
cloud-controller-manager
) โ Integrates Kubernetes with cloud providers (AWS, GCP, Azure, etc.).
๐น 2. Components of the Kubernetes Master Node
1๏ธโฃ Kube API Server (kube-apiserver
) โ The Gateway of Kubernetes ๐ช
๐ก Think of it as the "front desk" of Kubernetes, handling all requests.
โ Key Responsibilities:
Acts as the entry point for all administrative tasks.
Exposes a RESTful API for communication (kubectl, UI, automation tools).
Validates incoming requests and forwards them to the right components.
Handles authentication and authorization (RBAC, tokens, certificates).
Only component that directly communicates with
etcd
(Kubernetes database).
๐๏ธ How it Works:
A user runs a command like
kubectl apply -f deployment.yaml
.kube-apiserver
validates the request and updates theetcd
database.Other components (scheduler, controllers) pick up the changes and act accordingly.
๐ง Example API Call (Using cURL)
curl -k -X GET https://<master-node-ip>:6443/api/v1/nodes \
--header "Authorization: Bearer <your-token>"
This fetches all nodes in the cluster.
๐ Why is the API Server Critical?
โ
Every interaction with the Kubernetes cluster goes through it.
โ
It ensures security, validation, and authentication of requests.
โ
High availability is critical (usually runs in multiple replicas).
2๏ธโฃ Etcd โ The Brain of Kubernetes ๐ง
๐ก Think of etcd
as Kubernetes' "memory" where all cluster data is stored.
โ Key Responsibilities:
Stores all cluster data in a distributed key-value store.
Holds configuration details, state, metadata, and secrets.
Ensures data consistency across the cluster.
Used by the API Server to get the current state of the cluster.
๐๏ธ How it Works:
When you create a Deployment,
kube-apiserver
stores it in etcd.Other components check
etcd
to see what they need to do.
๐ Example: Querying etcd Manually
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
--cert=/etc/kubernetes/pki/etcd-server.crt \
--key=/etc/kubernetes/pki/etcd-server.key \
--cacert=/etc/kubernetes/pki/etcd-ca.crt get /registry/pods --prefix
This command retrieves all stored Pods in etcd
.
๐ Why is etcd Critical?
โ
Without etcd
, Kubernetes cannot function.
โ
Highly distributed & fault-tolerant (runs on multiple master nodes).
โ
Needs regular backups to prevent cluster failure.
3๏ธโฃ Kube Scheduler (kube-scheduler
) โ The Brains Behind Pod Placement ๐ฏ
๐ก The "traffic controller" of Kubernetes that decides where to run new Pods.
โ Key Responsibilities:
Watches for new unscheduled Pods in the cluster.
Decides which node should run each Pod.
Uses a scoring system based on:
Node capacity (CPU, memory, disk, network).
Node labels and taints (to match workloads to nodes).
Affinity/anti-affinity rules.
Custom constraints defined by admins.
๐๏ธ How it Works:
A Pod is created, but it doesn't have a node assigned yet.
kube-scheduler
evaluates all available nodes.It selects the best node and assigns the Pod.
The assignment is sent to the API Server, which updates etcd.
๐ Example: Checking Scheduler Decisions
kubectl get events --sort-by=.metadata.creationTimestamp
This shows scheduling events, like when a Pod was placed on a node.
๐ Why is the Scheduler Important?
โ
Ensures efficient resource usage across the cluster.
โ
Prevents overloading nodes (avoids running too many Pods on one node).
โ
Can be customized to handle different scheduling rules.
4๏ธโฃ Kube Controller Manager (kube-controller-manager
) โ The Automated Operator ๐ค
๐ก Think of this as an "auto-pilot" that keeps the cluster running smoothly.
โ Key Responsibilities:
Runs multiple controllers to maintain the cluster state.
Ensures that desired state = actual state.
Automatically fixes issues (e.g., restarts failed Pods).
๐๏ธ Key Controllers Inside kube-controller-manager
:
Node Controller โ Detects when a node goes offline and reschedules Pods.
Replication Controller โ Ensures the correct number of Pods are running.
Endpoints Controller โ Manages networking and service discovery.
Service Account Controller โ Manages authentication for Pods.
๐ Example: Checking Controller Actions
kubectl get pods --all-namespaces
Shows which Pods are being managed by controllers.
๐ Why is it Important?
โ
Ensures self-healing โ if something breaks, it fixes it automatically.
โ
Maintains the desired cluster state.
5๏ธโฃ Cloud Controller Manager (cloud-controller-manager
) โ The Cloud Connector โ๏ธ
๐ก Used in cloud environments to integrate Kubernetes with AWS, GCP, Azure, etc.
โ Key Responsibilities:
Manages cloud-specific resources like:
Load balancers (AWS ELB, GCP LB).
Storage (AWS EBS, Azure Disks).
Node management (adding/removing cloud VMs).
Separates cloud provider logic from core Kubernetes code.
๐ Why is it Important?
โ
Allows hybrid cloud & multi-cloud support.
โ
Decouples cloud-specific operations from Kubernetes core.
๐น Conclusion: How Master Node Works in Kubernetes
1๏ธโฃ User requests a new Pod (kubectl apply -f app.yaml
).
2๏ธโฃ kube-apiserver
validates the request & stores it in etcd
.
3๏ธโฃ kube-scheduler
finds the best node for the Pod.
4๏ธโฃ kube-controller-manager
ensures the Pod is running correctly.
5๏ธโฃ If running on a cloud, cloud-controller-manager
integrates cloud services.
๐ฅ Final Thoughts
The Master Node is the "brain" of Kubernetes, managing everything.
Without
etcd
, Kubernetes would lose all state.The API Server is the most important component, handling all requests.
The Scheduler and Controller Manager ensure smooth automation.
Cloud Controller Manager helps with multi-cloud deployments.
๐ Worker Node Components in Kubernetes (K8s) โ Explained in Detail
In Kubernetes (K8s), the Worker Node is responsible for running application workloads in the form of Pods. While the Master Node controls and manages the cluster, the Worker Node executes workloads as instructed by the Master.
๐น 1. Overview of Worker Node Components
Each Worker Node contains the following major components:
1๏ธโฃ Kubelet โ The agent that runs on each worker node and communicates with the Master.
2๏ธโฃ Container Runtime โ Runs containers inside Pods (e.g., Docker, containerd, CRI-O).
3๏ธโฃ Kube Proxy โ Handles networking and ensures communication between services.
4๏ธโฃ Pods โ The smallest unit in Kubernetes, containing one or more containers.
๐น 2. Components of the Kubernetes Worker Node
1๏ธโฃ Kubelet โ The Nodeโs Brain ๐ง
๐ก The "worker node manager" that ensures Pods run properly.
โ Key Responsibilities:
Registers the worker node with the Kubernetes Master.
Communicates with the API Server to get assigned Pods.
Ensures Pods are running on the node as per desired state.
Monitors Pod health and reports back to the Master.
Manages Pod lifecycle (starting, stopping, and restarting).
๐๏ธ How it Works:
1๏ธโฃ The Master Node assigns a Pod to a worker node.
2๏ธโฃ The kubelet on that node fetches Pod details from the API Server.
3๏ธโฃ It ensures the correct containers are running using the Container Runtime.
4๏ธโฃ If a container crashes, kubelet restarts it automatically.
๐ง Example: Checking Kubelet Logs
journalctl -u kubelet -f
This shows live logs of the kubelet
process.
๐ Why is Kubelet Important?
โ
Ensures Pods stay in the desired state.
โ
Restarts failed Pods automatically.
โ
Reports node health to the Master.
2๏ธโฃ Container Runtime โ The Engine that Runs Containers โ๏ธ
๐ก The "engine" that runs the actual containers inside Kubernetes Pods.
โ Key Responsibilities:
Pulls container images from Docker Hub, AWS ECR, GCP Artifact Registry, etc.
Runs containers inside Pods.
Handles container networking & storage.
Ensures containers are started, stopped, and restarted when needed.
๐๏ธ Common Container Runtimes in Kubernetes:
Docker (older, widely used but being deprecated in K8s).
containerd (lightweight and optimized for Kubernetes).
CRI-O (developed specifically for Kubernetes).
Podman (alternative to Docker).
๐ง Example: Checking Running Containers
crictl ps
This lists all running containers on a node.
๐ Why is the Container Runtime Important?
โ
Runs the actual application workloads inside containers.
โ
Fetches and starts containers as per kubelet instructions.
โ
Supports different container runtimes for flexibility.
3๏ธโฃ Kube Proxy โ The Network Bridge ๐
๐ก Handles networking and ensures communication between Pods and Services.
โ Key Responsibilities:
Maintains networking rules to route traffic between Pods.
Handles Load Balancing inside the cluster.
Uses iptables, IPVS, or eBPF to route traffic efficiently.
Enables communication between services, even across nodes.
๐๏ธ How it Works:
1๏ธโฃ A Pod needs to communicate with another Pod on a different node.
2๏ธโฃ kube-proxy
sets up networking rules to enable communication.
3๏ธโฃ The request is routed correctly to the destination Pod.
๐ง Example: Checking Kube Proxy Logs
journalctl -u kube-proxy -f
This shows live logs of the kube-proxy
process.
๐ Why is Kube Proxy Important?
โ
Enables seamless networking between Pods.
โ
Handles Load Balancing for services.
โ
Supports multiple networking modes (iptables, IPVS, eBPF).
4๏ธโฃ Pods โ The Smallest Unit in Kubernetes ๐
๐ก A "Pod" is a wrapper around one or more containers.
โ Key Responsibilities:
Runs application containers inside it.
Shares network and storage among its containers.
Managed by Kubernetes through Deployments, StatefulSets, DaemonSets, etc.
๐๏ธ Example Pod YAML Definition:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80
kubectl apply -f my-pod.yaml
This deploys a simple Nginx Pod on a worker node.
๐ Why are Pods Important?
โ
Encapsulate applications inside containers.
โ
Can have multiple containers sharing storage & networking.
โ
Can be scaled easily using Deployments & Auto-Scaling.
๐น 3. How the Worker Node Works in Kubernetes
1๏ธโฃ The Master Node assigns Pods to Worker Nodes.
2๏ธโฃ The kubelet fetches Pod details from the API Server.
3๏ธโฃ The Container Runtime pulls images and runs containers.
4๏ธโฃ Kube Proxy sets up networking rules for communication.
5๏ธโฃ The Pod runs the application and serves requests.
๐น 4. Kubernetes Worker Node vs. Master Node
Feature | Master Node ๐ง | Worker Node ๐๏ธ |
Purpose | Controls and manages cluster | Runs applications |
Components | API Server, etcd, Scheduler, Controller Manager | Kubelet, Container Runtime, Kube Proxy, Pods |
Manages | Scheduling, cluster state, networking | Running Pods and containers |
Communication | Talks to Worker Nodes | Reports to Master Node |
Runs Applications? | โ No | โ Yes |
๐ฅ Conclusion
Worker Nodes are where applications actually run in Kubernetes.
The kubelet ensures Pods are running as per the desired state.
The Container Runtime (Docker/containerd/CRI-O) runs containers.
The kube-proxy handles networking and communication between Pods.
Pods are the smallest deployable unit in Kubernetes.