Control plane
A node joins the cluster
Autoscaler, bootstrap, Ready
A cluster's nodes are machines someone has to start. When a Pod fits on no node, an autoscaler asks the cloud for one more, and the new machine has to prove who it is before the API server lets it in. Follow node-3 from an Auto Scaling group to a Ready node: a bootstrap token, a certificate signed by the cluster, a Node object, the DaemonSets that wire up its network, and the Pod that was waiting for it.
- Autoscaler
- Cluster Autoscaler · AWS Auto Scaling group
- New node
- node-3 · 10.0.1.13 · Pods 10.244.3.0/24
- Joins with
- kubeadm join · TLS bootstrapping
- Pending to running
- ≈ 70 s in this run
Read the whole lesson as text
1. Nowhere to go
You scale web to four replicas. The ReplicaSet creates the Pod at once, but the scheduler can't place it: it asks for 500m CPU, and node-1 and node-2 each have less than that left unreserved. The scheduler doesn't fail anything. It writes PodScheduled=False with the reason Unschedulable on the Pod, records a FailedScheduling event, and parks the Pod until something in the cluster changes.
- You ask for a fourth web Pod.
- The ReplicaSet controller creates the Pod, with no node yet.
- No node has room. The scheduler marks the Pod Unschedulable and sets it aside.
2. The autoscaler notices
Cluster Autoscaler runs as a Deployment, here on node-1. Every 10 seconds it looks for Pods the scheduler marked Unschedulable. For each node group it knows, here one AWS Auto Scaling group of m6i.xlarge machines, it builds a template node and runs the scheduler's own filters against it. The Pod would fit on one more of those, so it raises the group's desired capacity from 2 to 3. It never creates an instance itself, and never touches the Pod.
- On its next loop, the autoscaler finds the Pod the scheduler gave up on.
- It checks the Pod against a template node from the group: it would fit.
- The autoscaler asks AWS for one more machine in the group.
3. A machine
The Auto Scaling group launches an instance from its launch template and it boots as node-3, 10.0.1.13. Kubernetes doesn't know it exists. The template's user data runs kubeadm join, with the API server's address, a bootstrap token and a hash of the cluster's CA certificate. kubeadm first reads the public cluster-info ConfigMap, checks that the CA in it matches the hash, so it knows it is talking to the right cluster, then writes a bootstrap kubeconfig and starts the kubelet.
- AWS starts a new instance from the group's launch template.
- kubeadm reads the cluster's public information and checks it against the CA hash it was given.
4. TLS bootstrap
The kubelet has a token that may do little more than one thing: ask for a certificate. It makes a key pair and sends a CertificateSigningRequest for the name system:node:node-3 in group system:nodes. The controller manager's approver checks that the requester's group may ask for a node client certificate and approves it. Its signer signs it with the cluster CA. The kubelet downloads the certificate, writes a kubeconfig that uses it, and from now on is node-3.
- The kubelet, using the bootstrap token, asks for a client certificate.
- The approving controller sees a node client request from a bootstrapper, which RBAC allows, and approves it.
- The signing controller signs it with the cluster CA and writes the certificate into the CSR's status.
- The kubelet reads its certificate and switches to it. The bootstrap token is no longer used.
5. Register
With its new identity, the kubelet creates the Node object node-3 with its capacity, addresses and labels, and starts renewing a Lease in kube-node-lease. The NodeRestriction admission plugin makes sure system:node:node-3 can only write node-3. The node isn't Ready: containerd has no network configuration yet, so the kubelet reports Ready=False. The controller manager reacts twice: its node lifecycle controller taints node-3 not-ready, and its node IPAM controller gives it a slice of the Pod network, 10.244.3.0/24.
- The kubelet registers node-3.
- The controller manager taints node-3 not-ready and gives it the next free /24 of the Pod network.
- The kubelet creates its Lease and will renew it every 10 seconds from now on.
6. DaemonSets arrive
The DaemonSet controller sees a new node and creates a kube-proxy Pod and a kube-flannel Pod for it. Both tolerate the not-ready taint, because they are what makes the node ready. flannel reads node-3's Pod CIDR, writes its subnet file and installs its CNI configuration in /etc/cni/net.d. containerd finds the configuration, its network is ready, and on its next status update the kubelet reports Ready=True. The controller manager lifts the not-ready taint.
- The DaemonSet controller creates one kube-proxy and one kube-flannel Pod for node-3.
- node-3's kubelet sees both Pods. They use the host's network, so they need no CNI to start.
- flannel takes node-3's Pod CIDR, writes its subnet file and installs the CNI configuration.
- containerd reports its network ready, and the kubelet reports node-3 Ready.
- The node lifecycle controller sees Ready=True and removes the not-ready taint.
7. The Pod lands
The scheduler watches Nodes too. node-3's update is the kind of event that could help a Pod that failed for lack of CPU, so the scheduler moves the waiting Pod back to its active queue. This time node-3 passes every filter, with nearly four CPUs free, and the scheduler binds the Pod there. node-3's kubelet pulls the image, starts the container, and once the readiness probe passes the Pod joins the Service's endpoints.
- The scheduler's Node watch delivers node-3's update, and the waiting Pod goes back in the queue.
- node-3 has room. The scheduler binds the Pod to it.
- node-3's kubelet picks up its first application Pod.
- The container is up and its readiness probe passes.
8. And back down
Traffic falls and you scale web back to three. The ReplicaSet removes the newest Pod, which is the one on node-3. Now node-3 runs only DaemonSet Pods and its requests are far below half its capacity. The autoscaler counts it unneeded, and after 10 minutes of that, removes it: it taints the node so nothing new lands there, evicts what is left through the Eviction API, which respects PodDisruptionBudgets, and asks AWS to terminate the instance and shrink the group.
- You scale web back to three. The Pod on node-3 is the youngest, so it goes.
- node-3 has been unneeded for 10 minutes. The autoscaler taints it and evicts what's left.
- The autoscaler terminates node-3's instance and lowers the group's desired capacity in the same call.
- The instance shuts down. Once it is gone from AWS, its Node object is deleted too.
Summary
No component creates nodes inside Kubernetes. The autoscaler only asks the cloud for a machine when a Pod is Unschedulable. The machine proves itself with a short-lived bootstrap token, trades it for a certificate the cluster signs, registers a Node and stays NotReady until its DaemonSets set up the network. Then the scheduler's queue, woken by the changed Node, places the waiting Pod. Scaling down runs the other way: unneeded, drained, terminated.
Next lesson: Draining a node