Architecture
The API server, etcd, scheduler, controllers, kubelet, and kube-proxy
A Kubernetes cluster is a database of desired state with a set of programs that each watch part of it and act. Everything goes through one front door, the API server.
kubectl get pods -n kube-system -o wide
NAME STATUS NODE
etcd-lab-control-plane Running lab-control-plane
kube-apiserver-lab-control-plane Running lab-control-plane
kube-controller-manager-lab-control-plane Running lab-control-plane
kube-scheduler-lab-control-plane Running lab-control-plane
coredns-559f6c778d-7vjpk Running lab-control-plane
kube-proxy-wcgbz Running lab-worker2 # one per node
kindnet-wxdtl Running lab-worker2 # one per node (the network plugin)
metrics-server-995d47bd7-ml8q7 Running lab-worker3
kube-state-metrics-7cfd7f4c58-vpndr Running lab-worker3The control plane
| Component | Does |
|---|---|
| kube-apiserver | The only thing anyone talks to. Authenticates, authorizes, validates, runs admission (Pod Security, defaults), stores objects, and serves watches: streams of changes |
| etcd | The database. A Raft-replicated key-value store (one member here; three or five in production). Lose it without a backup and the cluster forgets everything |
| kube-scheduler | Watches for pods with no node, picks one (resources, spread, affinity, taints, volume topology) and writes the choice back |
| kube-controller-manager | Dozens of controllers: Deployment, ReplicaSet, StatefulSet, node lifecycle, endpoints, garbage collection... each a reconciliation loop |
On every node
| Component | Does |
|---|---|
| kubelet | Watches for pods bound to its node, starts their containers through the runtime (containerd), runs probes, reports status, kills containers over their memory limit (via the kernel) |
| kube-proxy | Programs the node's packet rules (iptables or nftables) so Service IPs reach pod IPs |
| CNI plugin (kindnet here) | Gives each pod an IP and routes between nodes; enforces NetworkPolicies if it supports them |
One Deployment, start to finish
kubectl applysends a Deployment to the API server, which stores it.- The Deployment controller sees a Deployment with no ReplicaSet and creates one. The ReplicaSet controller sees 0 of 3 pods and creates 3 pod objects, with no node.
- The scheduler sees 3 unscheduled pods and binds each to a node.
- Each kubelet sees a pod bound to its node, pulls the image, starts the container, runs the probes, and reports status.
- The endpoints controller sees ready pods matching the Service's selector and adds them to its EndpointSlice. kube-proxy and the Gateway's NGINX see that and start sending traffic.
No component calls another. Each watches the API server for the objects it cares about and writes its results back. That's why the system heals itself: if a step fails, the gap is still visible, and the loop tries again.
The node lifecycle controller is a loop too: kubelets renew a Lease
object every few seconds, and when a node's lease stops being renewed for
the grace period, the controller marks the node Unknown and taints it.
In this module's node-failure lab that took 45 seconds, and the
pods on the dead node were evicted 300 seconds after that. See
Node Failure.
Talking to the API
Every object has a spec (what you want) and a status (what the
controllers last observed). Debugging Kubernetes is mostly comparing the
two, and reading the events controllers emit when they can't close the
gap.
Lab
- Run
kubectl get events -n shop --watchin one terminal andkubectl -n shop scale deploy web --replicas=5in another. Name the component behind each event. - Stop the scheduler:
docker exec lab-control-plane mv /etc/kubernetes/manifests/kube-scheduler.yaml /tmp/. Scalewebto 6. What state are the new pods in? Move the file back. - Read
kubectl get lease -n kube-node-leasetwice, ten seconds apart.