Kubernetes Architecture
Understanding Kubernetes architecture is crucial for working with it effectively. A Kubernetes cluster consists of a control plane and one or more worker nodes.
Cluster Overview
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Control Plane β
β ββββββββββββ βββββββββββββ ββββββββββββ ββββββββββ β
β β API β β Scheduler β βControllerβ β etcd β β
β β Server β β β β Manager β β β β
β ββββββ¬ββββββ βββββββ¬ββββββ ββββββ¬ββββββ βββββ¬βββββ β
βββββββββΌβββββββββββββββΌβββββββββββββββΌβββββββββββββΌβββββββ
β β β β
βββββββββΌβββββββββββββββΌβββββββββββββββΌβββββββββββββΌβββββββ
β β Worker Nodes β β β
β ββββββ΄ββββββ βββββββ΄ββββββ ββββββ΄ββββββ β
β β kube β β kube β β kube β β
β β -proxy β β -proxy β β -proxy β β
β ββββββ¬ββββββ βββββββ¬ββββββ ββββββ¬ββββββ β
β ββββββ΄ββββββ βββββββ΄ββββββ ββββββ΄ββββββ β
β βContainer β βContainer β βContainer β β
β β Runtime β β Runtime β β Runtime β β
β ββββββββββββ βββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Control Plane Components
API Server (kube-apiserver) β The front door to the cluster. All communication between components goes through the API server. kubectl talks to the API server.
etcd β A distributed key-value store that holds all cluster state. Think of it as the cluster's database. Without etcd, Kubernetes has no memory.
Scheduler (kube-scheduler) β Watches for newly created pods with no assigned node and selects a node for them to run on based on resource requirements and constraints.
Controller Manager (kube-controller-manager) β Runs controller loops that regulate the state of the system. For example, the ReplicaSet controller ensures the desired number of pods are always running.
Worker Node Components
kubelet β An agent running on each node that ensures containers are running in a pod. It communicates with the container runtime to start, stop, and monitor containers.
kube-proxy β Maintains network rules on nodes, enabling Services to route traffic to the correct pods.
Container Runtime β The software responsible for running containers. Common runtimes include containerd, CRI-O, and Docker (deprecated).
How a Deployment Works
1. You run: kubectl apply -f deployment.yaml
β
βΌ
2. API Server stores the desired state in etcd
β
βΌ
3. Controller Manager notices the new Deployment
and creates a ReplicaSet
β
βΌ
4. Scheduler assigns the ReplicaSet's Pods to nodes
β
βΌ
5. Kubelet on each node tells the container runtime
to start the containers
β
βΌ
6. Everything is now running! K8s continuously
reconciles desired vs actual state