Sub topic 16
Keeping headroom with placeholder pods
This chapter assumes you know how Pending pods trigger a node autoscaler, which the Cluster Autoscaler and Karpenter chapters cover. It also assumes you know pod priority and PodDisruptionBudgets at a basic level.
The problem: scale-up takes time
A node autoscaler reacts to Pending pods. Launching a node, joining it to the cluster and pulling images can take from one to several minutes. During that time the new pods wait. For latency-sensitive services, that delay is visible to users.
Overprovisioning removes the wait. You run low-priority placeholder pods that hold spare capacity. When real pods arrive, the scheduler evicts the placeholders and places the real pods in the freed space immediately. The evicted placeholders become Pending, and that triggers the autoscaler to add a node in the background.
Defining the placeholders
You need two objects. A PriorityClass with a negative value ranks the placeholders below every normal pod, because pods without a class have priority 0. A Deployment of pause pods then requests the headroom you want.
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: overprovisioning
value: -10
globalDefault: false
description: Placeholder pods that real workloads can preempt.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: overprovisioning
spec:
replicas: 2
selector:
matchLabels:
app: overprovisioning
template:
metadata:
labels:
app: overprovisioning
spec:
priorityClassName: overprovisioning
containers:
- name: pause
image: registry.k8s.io/pause:3.9
resources:
requests:
cpu: "1"
memory: 1GiThe pause container does nothing, so it costs only the reserved requests. Headroom equals replicas multiplied by the requests. Here that is 2 CPUs and 2Gi.
Sizing and tuning
- Make each placeholder at least as large as your biggest common pod. A real pod needing 2 CPUs cannot fit in the space of one 1-CPU placeholder, unless another placeholder on the same node is also evicted.
- Choose the replica count from how much burst you expect during one node launch time.
- Placeholders cost money, because they keep real capacity allocated. Treat the headroom as a deliberate expense.
Common errors
- Placeholders are never evicted. Check that the priority value is lower than your real pods' priority. Also check that the real pods do not have a
preemptionPolicy: Neverclass. - Placeholders block scale-down. They count as running pods. The Cluster Autoscaler ignores pods it cannot move only when they are safe to evict, so check that nodes with placeholders still scale down as expected. On Karpenter, they also keep nodes from being consolidated away, which is the intended trade-off.
- The autoscaler ignores the Pending placeholders. The Cluster Autoscaler has a
--expendable-pods-priority-cutoffoption, default-10. Pods with a priority below the cutoff are treated as expendable and do not trigger scale-up. A placeholder at exactly-10still triggers it. A value such as-100does not, which defeats the purpose.
Check your understanding
Exercise
A Deployment of placeholder pods requests 500m CPU each, and your real pods request 2 CPUs each. A burst of real pods arrives. Why might the headroom fail to help, and how do you fix it?
Show answer
One placeholder frees only 500m CPU, which is too small for a 2-CPU pod. The scheduler would have to evict several placeholders on the same node, and may not find a fit. Fix it by making the placeholder requests at least as large as the real pods, for example 2 CPUs each, and by choosing the replica count for the burst size you expect.
Exercise
Why must the placeholder PriorityClass value be lower than 0?
Show answer
Pods with no priority class have priority 0. The scheduler preempts only lower-priority pods, so a negative value ensures that every normal pod can evict a placeholder.