Sub topic 13
How Karpenter picks and launches nodes
This chapter assumes you know Pod resource requests, how a Pod becomes Pending, and the NodePool and EC2NodeClass objects from the previous chapter. It covers what Karpenter does between seeing a Pending Pod and having a Ready node.
From Pending Pod to NodeClaim
Karpenter watches for Pods that the scheduler marked unschedulable. It does not look at node groups. It collects a batch of these Pods, then works out what capacity would let them run.
The batching step waits for a short idle period, so a burst of Pods produces one decision instead of many. After that, Karpenter runs a scheduling simulation with three inputs:
- The Pods' requests, node selectors, affinity rules, tolerations and topology spread constraints.
- The requirements and limits of each NodePool.
- The instance types and offerings the EC2NodeClass can reach in its subnets.
The output is one or more NodeClaims. A NodeClaim is a request for a single node, with the requirements that node must meet. Karpenter creates the NodeClaim, then calls the EC2 API to launch an instance for it.
How the instance type is chosen
Karpenter sums the requests of the Pods that will share a node and adds the overhead of the kubelet and system daemons. It then filters the available instance types to those that satisfy every constraint, such as architecture, zone, capacity type and any node.kubernetes.io/instance-type selector.
It packs Pods onto the candidate node using a first-fit-decreasing approach: larger Pods are placed first, and smaller ones fill the gaps. Several Pods may land on one node, or the batch may need several nodes.
Karpenter then sends EC2 a list of suitable instance types instead of one. Using the EC2 Fleet API, it asks for the lowest-priced option among them. For on-demand capacity it picks the cheapest type that fits. For spot, it uses a price-capacity-optimized strategy, which favors pools that are both cheap and less likely to be interrupted.
Running the test
Reuse the inflate Deployment from earlier chapters, which requests 1 CPU and 1Gi per Pod. Scale it up and watch what happens:
kubectl scale deployment inflate --replicas=10
kubectl get nodeclaims
kubectl get nodes -wYou should see a NodeClaim appear within seconds, followed by a node. With ten Pods at 1 CPU each, Karpenter will often choose one larger instance rather than ten small ones, if the NodePool allows it.
Why a launch can fail
A NodeClaim that never becomes a node is the usual symptom. Common causes:
- The NodePool has reached its
limits, so Karpenter refuses to add capacity. - No instance type matches the combined requirements, for example a Pod that asks for an architecture the NodePool excludes.
- The EC2NodeClass selectors match no subnets or security groups, so there is nowhere to launch.
- EC2 reports insufficient capacity or a service quota error. Karpenter marks that offering as unavailable for a while and tries another type or zone.
Exercise
Ten Pods each request 1 CPU. The NodePool allows many instance types. Why might Karpenter launch one node instead of ten?
Show answer
Karpenter simulates scheduling for the whole batch and packs Pods together. It picks instance types that fit the combined requests, so a single larger node can satisfy all ten Pods if constraints allow.