Kubernetes Architecture: Control Plane and Nodes
In the last lesson, kubectl apply replied with one line, and moments later three pods ran on machines you never logged into. Something chose those machines and something started the containers. This lesson opens up the Kubernetes architecture behind that: the control plane that decides, the worker nodes that do the work, and the path one request takes between them.
The control plane: the head office
A cluster has two halves. The control plane stores the desired state and decides what runs where; the worker nodes are the machines that run your pods. In the diagram, notice that every line ends at one box: the API server.
The kube-apiserver, or API server, is the front desk. It serves the Kubernetes API (application programming interface): the requests the cluster understands, such as "create this Deployment". Every request, from you or another component, arrives here over HTTPS. The API server checks who is asking and whether they are allowed, validates the object and saves it.
etcd holds the record books. It is a key-value store, a database that saves each value under a unique name, its key, and holds all cluster state. Only the API server reads or writes it. Lose its data without a backup and the cluster forgets every object, so production clusters run etcd on three or five machines that keep copies in sync.
The kube-scheduler watches for new pods that have no node yet. It filters out nodes that cannot take a pod, for example those without enough CPU or memory left for what the pod asks for, scores the rest and picks the best. It records the choice through the API server; it never starts a container.
The kube-controller-manager runs the controllers from lesson 7, each watching one kind of object, such as Deployments or nodes, and closing the gap between desired and actual state. Many controllers are bundled into this one program.
Worker nodes: the branches
A worker node is a machine, physical or virtual, that runs pods. Its branch manager is the kubelet, an agent on every node. It watches the API server for pods assigned to its node, has the container runtime start their containers, restarts containers that crash and reports each pod's status back.
kube-proxy keeps each node's network rules up to date, for example iptables rules, the Linux kernel's packet-forwarding rules, so that traffic sent to a Service (a stable address in front of changing pods, lesson 11) reaches one of its pods. The kernel forwards the traffic; kube-proxy only writes the rules.
The container runtime from lesson 1 creates the containers. Common choices are containerd, which Docker Engine also uses underneath, and CRI-O. The kubelet talks to the runtime through the Container Runtime Interface (CRI). Kubernetes 1.24 dropped built-in support for Docker Engine, yet images built with Docker still run, because they follow the OCI standard from lesson 2.
Tools such as kind, which you install in lesson 17, run the control plane itself as pods. You can list them, with kube-proxy, in the kube-system namespace, a named group of objects inside a cluster (lesson 16). Read along for now; the -n flag picks the namespace:
kubectl get pods -n kube-system
On a one-node kind cluster named lab, you should see something like this. It is trimmed: two coredns pods (the cluster's DNS server) and a kindnet pod (pod networking) are left out, and your suffixes and ages will differ.
NAME READY STATUS RESTARTS AGE
etcd-lab-control-plane 1/1 Running 0 12m
kube-apiserver-lab-control-plane 1/1 Running 0 12m
kube-controller-manager-lab-control-plane 1/1 Running 0 12m
kube-proxy-9vz7c 1/1 Running 0 12m
kube-scheduler-lab-control-plane 1/1 Running 0 12m
The kubelet and containerd are missing because they are not pods: they run as ordinary services on each node, since something has to start pods in the first place. With no cluster to talk to, kubectl ends with The connection to the server localhost:8080 was refused instead.
The control loop: observe, compare, act
Every controller, and the kubelet too, runs a control loop: observe the actual state, compare it with the desired state, act to close any gap, then start again, like a thermostat. Nobody hands a controller orders. Each one watches the API server, which streams it a notice whenever an object it cares about is created, changed or deleted.
In the flowchart, a controller keeps three copies of a pod. It acts only by creating or deleting Pod objects through the API server; the kubelets then start or stop the containers. Because it compares instead of following a script, it closes the gap however it arose: a lost node, a deleted pod or an extra copy.
Follow one request from kubectl to a container
Say app.yaml holds the web Deployment from lesson 7, asking for three nginx pods, and you run kubectl apply -f app.yaml. As in lesson 7, it prints deployment.apps/web created almost at once. Here is what happens around that reply:
- kubectl sends the file over HTTPS to the API server named in your kubeconfig, the file that tells kubectl which cluster to use and how to log in.
- The API server checks who you are and what you may do, and validates the YAML.
- It saves the Deployment in etcd and replies. Nothing runs yet.
- The Deployment controller creates a ReplicaSet (lesson 10), whose controller creates three Pod objects with no node.
- The scheduler picks a node for each pod and saves the choice;
kubectl get pods -o wideshows it in the NODE column. - On each chosen node, the kubelet sees its new pod and has containerd pull the image and start the container.
- The kubelet reports the pod as Running, and the API server saves that in etcd.
In the diagram, notice that kubectl's reply comes after step 3, before any pod exists. kube-proxy plays no part yet; it acts once a Service points at these pods.
Managed Kubernetes: someone else runs the head office
Running a control plane well is real work: redundant API servers, etcd backups, certificates and upgrades. Managed Kubernetes services such as Amazon Elastic Kubernetes Service (EKS), Google Kubernetes Engine (GKE) and Azure Kubernetes Service (AKS) do it for you. The provider runs the control plane on its own machines and hands you its API server address.
You still own the workloads: Deployments, Services, settings and access rules. You usually manage the worker nodes too, their size, count and upgrades, though managed node groups and modes such as GKE Autopilot take over some or all of that. It is the shared responsibility model applied to a cluster.
So on a managed cluster, kubectl get nodes lists only worker nodes, and kube-system has no API server or etcd pods. The provider also runs an optional fifth control plane part, the cloud-controller-manager, which talks to the cloud's API, for example to create load balancers.
Check yourself
Your cluster's control plane goes offline for ten minutes. What happens to running pods, and what stops working?
They keep serving: the kubelet and runtime on each node keep existing containers going on their own. What stops is anything needing a decision or a record: kubectl commands fail, no new pods are scheduled, and pods on a node that dies are not replaced until the control plane returns.
A new pod was accepted but has no node, so it never starts. Which component decides its next step, and what could hold it up?
The kube-scheduler, because placing new pods is its job, and no kubelet starts a pod that is not assigned to its node. If no node passes the filters, for example none has enough CPU or memory left for what the pod asks for, the pod waits; lesson 20 shows how to read the reason.
The scheduler crashes and restarts. Why does the cluster lose no information?
Because all cluster state lives in etcd behind the API server, not inside the scheduler. The restarted scheduler reads the current pods again and carries on placing any that still have no node; controllers recover the same way.
Go deeper
- Setup Kubernetes cluster monitoring the easy way: installs Prometheus and Grafana, with dashboards for these parts, from the API server and etcd to the kubelet.