๐Ÿš€Kubernetes Architecture๐Ÿš€

ยท

9 min read

๐Ÿš€ 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:

  1. API Server (kube-apiserver) โ€“ The front-end and gateway of Kubernetes.

  2. Controller Manager (kube-controller-manager) โ€“ Manages controllers that handle cluster operations.

  3. Scheduler (kube-scheduler) โ€“ Decides which node runs which Pod.

  4. Etcd โ€“ The key-value store that holds cluster data.

  5. 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:

  1. A user runs a command like kubectl apply -f deployment.yaml.

  2. kube-apiserver validates the request and updates the etcd database.

  3. 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:

  1. A Pod is created, but it doesn't have a node assigned yet.

  2. kube-scheduler evaluates all available nodes.

  3. It selects the best node and assigns the Pod.

  4. 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:

  1. Node Controller โ€“ Detects when a node goes offline and reschedules Pods.

  2. Replication Controller โ€“ Ensures the correct number of Pods are running.

  3. Endpoints Controller โ€“ Manages networking and service discovery.

  4. 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

FeatureMaster Node ๐Ÿง Worker Node ๐Ÿ—๏ธ
PurposeControls and manages clusterRuns applications
ComponentsAPI Server, etcd, Scheduler, Controller ManagerKubelet, Container Runtime, Kube Proxy, Pods
ManagesScheduling, cluster state, networkingRunning Pods and containers
CommunicationTalks to Worker NodesReports 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.

ย