Cluster Architecture
A Kubernetes cluster is a set of machines (physical or virtual) split into two roles:
- The control plane: the "brain". It stores the desired state, makes decisions (scheduling, scaling) and exposes the API.
- The worker nodes: the "muscle". They actually run your containers.
Small test clusters often run everything on one machine; production clusters usually have three control-plane machines (for high availability) and anywhere from a handful to thousands of workers.
Control plane components
| Component | Job |
|---|---|
| kube-apiserver | The front door. Every client (kubectl, controllers, kubelets) reads and writes cluster state only through its REST API. It authenticates, authorises and validates every request. |
| etcd | A consistent, distributed key-value store holding all cluster objects. Only the API server talks to it. |
| kube-scheduler | Watches for new Pods with no node assigned and picks a node for each one. |
| kube-controller-manager | Runs the built-in controllers (ReplicaSet, Deployment, Node, Job, EndpointSlice, …), each a reconcile loop. |
| cloud-controller-manager | Optional. Talks to the cloud provider: creates load balancers, attaches disks, notices deleted VMs. |
Node components
| Component | Job |
|---|---|
| kubelet | An agent on every node. It watches the API for Pods assigned to its node, asks the container runtime to start them, runs health probes and reports status back. |
| container runtime | Actually runs containers: containerd or CRI-O, through the Container Runtime Interface (CRI). |
| kube-proxy | Programs the node's networking (iptables/IPVS rules) so Service IPs reach the right Pods. Some network plugins replace it. |
Add-ons such as the cluster DNS (CoreDNS), a network plugin (CNI, e.g. Calico or Cilium) and metrics-server complete a working cluster.
Everything goes through the API server
Components never call each other directly. They all watch the API server and react to changes. Following one kubectl apply of a Deployment through the system:
kubectlsends the Deployment to the API server, which validates it and stores it in etcd.- The Deployment controller sees a new Deployment and creates a ReplicaSet.
- The ReplicaSet controller sees a ReplicaSet wanting 3 Pods and creates 3 Pod objects (with no node yet).
- The scheduler sees unscheduled Pods and writes a node name into each one.
- The kubelet on each chosen node sees a Pod bound to it and starts the containers.
- The kubelet reports
Runningstatus back to the API server.
Here is that chain as a small event-driven model. Each component only reacts to objects in the shared store, exactly like the real system:
store = [] # stands in for etcd, accessed only through "the API"
log = []
def api_create(obj):
store.append(obj)
log.append(f"apiserver: stored {obj['kind']} {obj['name']}")
def deployment_controller():
for o in list(store):
if o["kind"] == "Deployment" and not o.get("handled"):
o["handled"] = True
api_create({"kind": "ReplicaSet", "name": o["name"] + "-rs", "replicas": o["replicas"]})
def replicaset_controller():
for o in list(store):
if o["kind"] == "ReplicaSet" and not o.get("handled"):
o["handled"] = True
for i in range(o["replicas"]):
api_create({"kind": "Pod", "name": f"{o['name']}-{i}", "node": None})
def scheduler(nodes):
pods = [o for o in store if o["kind"] == "Pod" and o["node"] is None]
for i, pod in enumerate(pods):
pod["node"] = nodes[i % len(nodes)]
log.append(f"scheduler: {pod['name']} -> {pod['node']}")
def kubelet(node):
for o in store:
if o["kind"] == "Pod" and o["node"] == node:
log.append(f"kubelet@{node}: started {o['name']}")
api_create({"kind": "Deployment", "name": "web", "replicas": 3})
deployment_controller()
replicaset_controller()
scheduler(["node-a", "node-b"])
for n in ["node-a", "node-b"]:
kubelet(n)
print("\n".join(log))apiserver: stored Deployment web
apiserver: stored ReplicaSet web-rs
apiserver: stored Pod web-rs-0
apiserver: stored Pod web-rs-1
apiserver: stored Pod web-rs-2
scheduler: web-rs-0 -> node-a
scheduler: web-rs-1 -> node-b
scheduler: web-rs-2 -> node-a
kubelet@node-a: started web-rs-0
kubelet@node-a: started web-rs-2
kubelet@node-b: started web-rs-1
etcd and quorum
etcd keeps several copies of the data and uses the Raft consensus algorithm: a write is only committed once a majority (a quorum) of members agree. That is why control planes come in odd sizes. A cluster of n members survives (n - 1) // 2 failures:
for members in range(1, 8):
quorum = members // 2 + 1
tolerated = members - quorum
print(f"{members} members: quorum {quorum}, survives {tolerated} failure(s)")1 members: quorum 1, survives 0 failure(s)
2 members: quorum 2, survives 0 failure(s)
3 members: quorum 2, survives 1 failure(s)
4 members: quorum 3, survives 1 failure(s)
5 members: quorum 3, survives 2 failure(s)
6 members: quorum 4, survives 2 failure(s)
7 members: quorum 4, survives 3 failure(s)
Notice that 4 members tolerate no more failures than 3, and 6 no more than 5: an even member costs more without adding resilience.
Tip: Back up etcd! It is the single source of truth. Losing it means losing every object definition in the cluster (the running containers would keep running for a while, but nothing could manage them).
Looking at a real cluster
kubectl get nodes -o wide
kubectl get pods -n kube-systemSample output:
NAME STATUS ROLES AGE VERSION INTERNAL-IP
demo-control-plane Ready control-plane 5m v1.34.0 172.18.0.2
demo-worker Ready <none> 5m v1.34.0 172.18.0.3
NAME READY STATUS RESTARTS AGE
coredns-674b8bbfcf-8r5vd 1/1 Running 0 5m
etcd-demo-control-plane 1/1 Running 0 5m
kube-apiserver-demo-control-plane 1/1 Running 0 5m
kube-controller-manager-demo-control-plane 1/1 Running 0 5m
kube-proxy-x7k2l 1/1 Running 0 5m
kube-scheduler-demo-control-plane 1/1 Running 0 5mIn many clusters the control-plane components themselves run as Pods in the kube-system namespace. Managed services (EKS, GKE, AKS) hide the control plane entirely and only show you the workers.
Go further: The Kubernetes Attack Surface maps the API server, kubelet and etcd as targets and checks a cluster's configuration.
Test yourself
Which component is the only one that talks to etcd directly?
- kubelet
- kube-scheduler
- kube-apiserver
- kube-proxy
What does the kube-scheduler do?
- Starts containers on a node
- Assigns a node to Pods that don't have one yet
- Stores the cluster state
- Restarts crashed containers
How many member failures can a 5-member etcd cluster survive?
- 1
- 2
- 3
- 4