Sub topic 11
Karpenter's node provisioning model
This chapter assumes you know Pods, Deployments, resource requests, and what a Pending pod is. It also assumes you have read how the Cluster Autoscaler works with node groups. Here you will see how Karpenter takes a different approach.
Groupless provisioning
The Cluster Autoscaler resizes node groups you define in advance. Each group is an Auto Scaling group with one instance type (or a few similar ones). Karpenter has no node groups. It watches for unschedulable pods and calls the cloud API directly to launch an instance that fits them.
The unit Karpenter creates is a NodeClaim. A NodeClaim is a request for one node, with the requirements and resource sizes that Karpenter computed from pending pods. Karpenter then launches the instance, waits for it to join the cluster, and binds the pods.
The control loop
Karpenter runs as a controller in your cluster. Its provisioning cycle has four steps:
- It sees pods that the scheduler marked unschedulable.
- It waits briefly to batch pods that arrive close together, so one decision covers many pods.
- It simulates scheduling those pods against the constraints you configured, and finds instance types that satisfy their requests, selectors, affinity, taints and topology rules.
- It creates a NodeClaim and launches the cheapest option that works.
Because it sizes nodes from pod requests, accurate requests matter even more than with node groups. A pod that requests 1 CPU and 1Gi gets a node chosen to hold it, and the pod's real usage is not considered.
Two kinds of configuration
You give Karpenter its rules with two Kubernetes resources:
| Resource | Scope | Answers |
|---|---|---|
| `NodePool` | Kubernetes side | What kinds of nodes may exist? Architecture, capacity type, limits, expiry, disruption policy |
| `EC2NodeClass` | AWS side | How are they launched? IAM role, AMI, subnets, security groups |
A NodePool points to an EC2NodeClass through nodeClassRef. Several NodePools can share one class. The next chapter covers the fields in detail.
Testing it
You can watch the model work with the inflate Deployment from earlier in the tutorial. It starts at zero replicas and requests 1 CPU and 1Gi per pod.
kubectl scale deployment inflate --replicas=10
kubectl get nodeclaims
kubectl get nodes -wWithin a minute or so you should see one or more NodeClaims appear, followed by nodes joining. Karpenter may choose a few large instances or one very large instance, depending on your NodePool. Scale the Deployment back to 0 and the nodes are removed by consolidation, covered in a later chapter.
Common errors
- Pods stay Pending and no NodeClaim appears. No NodePool matches the pod. Check the pod's node selectors, taints and tolerations against the NodePool requirements.
- A NodeClaim appears but the node never registers. The problem is usually on the AWS side: the IAM role, the subnet or security group tags, or the AMI selector in the EC2NodeClass.
- Nodes stop being created. The NodePool
limitsmay have been reached.
Exercise
A pod requests 6 CPU, and your cluster has only 4-CPU nodes. With Karpenter, what happens, and how does this differ from a Cluster Autoscaler node group of 4-CPU instances?
Show answer
Karpenter looks for any instance type allowed by the NodePool that has at least 6 CPU available and launches one. A Cluster Autoscaler group of 4-CPU instances cannot ever fit the pod, so the pod stays Pending until someone adds a group with larger instances.