CapacityBuffer
Quota reservation confirms that a Workload fits the quota of its ClusterQueue, but not that the nodes for its Pods exist. The CapacityBuffer admission check makes Kueue wait for that capacity with autoscalers that support CapacityBuffers, such as Karpenter. Kueue asks the autoscaler to keep room for the Workload’s Pods, and admits the Workload once the autoscaler reports that the capacity fits.
With the check, a Workload goes through these steps:
- Quota reservation: Kueue reserves quota for the Workload in its ClusterQueue.
- Capacity: Kueue creates a CapacityBuffer for each PodSet that requests a managed resource, with the PodSet’s admitted count and Pod template.
The autoscaler provisions nodes for the buffer and reports
Provisioning=Truewith reasonFitsExistingCapacityonce the buffer fits on existing nodes. The admission check then becomesReady. - Admission: once all its admission checks are
Ready, Kueue admits the Workload and the Job starts. Kueue holds the Job’s Pods with a scheduling gate until all Pods of a PodSet exist, then deletes that PodSet’s CapacityBuffer and removes the gate, so the Pods use the capacity that the buffer kept.
For example, an AI training Job requests 16 GPUs in a ClusterQueue with 32 GPUs of quota:
- Kueue reserves 16 GPUs of quota and creates a CapacityBuffer for the Job’s PodSet.
- The autoscaler launches four nodes with 4 GPUs each and reports
FitsExistingCapacity. - Kueue admits the Job. Its Pods are created with the scheduling gate, and once all of them exist, Kueue deletes the buffer and the Pods are scheduled on the new nodes.
CapacityBuffer admission check controller
The CapacityBuffer admission check controller is part of Kueue and is behind the CapacityBufferACC feature gate, which is disabled by default.
The check needs an autoscaler that serves the CapacityBuffer API (capacitybuffers.autoscaling.x-k8s.io) and reports FitsExistingCapacity.
In alpha, the check works with Karpenter with its CapacityBuffer support enabled.
If the gate is enabled but the CapacityBuffer API is not served, the controller is not started,
and Kueue removes the kueue.x-k8s.io/capacity-buffer scheduling gate from Pods that still have it.
A new AdmissionCheck for the controller does not become active, so its ClusterQueues are inactive.
Enable the CapacityBuffer admission check
CapacityBufferConfig is an alpha API. Kueue does not install its CRD by default.
If you installed Kueue with kubectl, run:
kubectl apply --server-side -f https://github.com/kubernetes-sigs/kueue/releases/download/v0.21.0/alpha-crds.yaml
If you installed Kueue with Helm, set enableAlphaAPIs to true:
helm upgrade kueue https://github.com/kubernetes-sigs/kueue/releases/download/v0.21.0/kueue-0.21.0.tgz \
--namespace kueue-system \
--reset-then-reuse-values \
--set enableAlphaAPIs=true
Then follow the
feature gates configuration instructions
to enable the CapacityBufferACC feature gate in the Kueue controller manager.
If you installed Kueue with Helm, add the gate to controllerManager.featureGates in your values instead, so that the next helm upgrade keeps it.
Usage
To use the CapacityBuffer admission check, create an AdmissionCheck
with kueue.x-k8s.io/capacity-buffer as .spec.controllerName, and a CapacityBufferConfig that the AdmissionCheck references in .spec.parameters.
Then reference the AdmissionCheck from the ClusterQueue, as detailed in Admission Check usage.
See below for a full setup.
CapacityBufferConfig
A CapacityBufferConfig is a cluster-scoped object that looks like the following:
apiVersion: kueue.x-k8s.io/v1alpha1
kind: CapacityBufferConfig
metadata:
name: capacity-buffer-config
spec:
managedResources:
- nvidia.com/gpu
timeoutSeconds: 600
retryStrategy:
backoffBaseSeconds: 60
backoffMaxSeconds: 1800
Where:
- managedResources - the resources that need a CapacityBuffer.
Kueue creates a CapacityBuffer only for the PodSets that request at least one of them.
If no PodSet requests one, the check is
Readywithout a CapacityBuffer. IfmanagedResourcesis empty or not set, every PodSet gets a CapacityBuffer. - timeoutSeconds - how long Kueue waits for the CapacityBuffers to reach
FitsExistingCapacity. The time is measured from the quota reservation, so it also covers CapacityBuffers that cannot be created. When it passes, the check isRetry: Kueue evicts the Workload, releases its quota, deletes its CapacityBuffers, and requeues it. If unset, Kueue waits until the capacity fits. - retryStrategy.backoffBaseSeconds - the base of the exponential backoff before a Workload evicted after
timeoutSecondsis requeued. The delays are aboutbackoffBaseSeconds * 2^(n-1), wherenis the number of retries. Defaults to 60. - retryStrategy.backoffMaxSeconds - the maximum backoff. Defaults to 1800. Kueue keeps retrying at this delay.
backoffBaseSeconds and backoffMaxSeconds must be at least 1, and backoffBaseSeconds must not be greater than backoffMaxSeconds.
Check the API definition for more details.
CapacityBuffers created by Kueue
For each PodSet that requests a managed resource, Kueue creates a PodTemplate and a CapacityBuffer, both named <workload>-<admission check>-<podset>.
The PodTemplate is the PodSet’s template with the node selector and tolerations of the ResourceFlavor the PodSet was assigned to,
so the autoscaler provisions nodes that match the flavor.
The CapacityBuffer uses the provisioning strategy buffer.x-k8s.io/active-capacity and the PodSet’s admitted count as its replicas.
Both objects are owned by the Workload and labeled kueue.x-k8s.io/managed=true.
Kueue deletes them when the Workload is evicted, finished, or deleted.
If a CapacityBuffer with the same name already exists and is not owned by the Workload, Kueue does not use it.
The check stays Pending until that object is removed, and timeoutSeconds still applies.
Holding the Pods
While a CapacityBuffer exists, the autoscaler keeps its capacity: it does not remove those nodes, and if other Pods use them, it adds nodes to refill the buffer. Kueue keeps each PodSet’s CapacityBuffer while the Job creates its Pods, so that the capacity stays protected, and holds the Pods until the buffer is deleted, so that they do not cause a refill:
- When the check becomes
Ready, it marks each PodSet that has a CapacityBuffer. When Kueue starts the Job, it adds thekueue.x-k8s.io/capacity-bufferscheduling gate to the Pod templates of those PodSets. - Once all Pods of a PodSet exist, Kueue deletes the PodSet’s CapacityBuffer and removes the gate from its Pods. Each PodSet is released separately, so a JobSet that starts its jobs in order releases each buffer when the Pods of that job exist.
- Pods that already exist at admission, such as plain Pods, or the Pods of a StatefulSet, LeaderWorkerSet, or Deployment, cannot be gated. They count toward the PodSet, so the buffer is deleted once all of them exist. If such Pods are created one at a time after admission, for example by a StatefulSet with ordered startup, the running Pods use the buffered capacity while the buffer still exists, and the autoscaler can add nodes to refill it.
Admission check states
| Situation | Check state and message |
|---|---|
| The CapacityBuffers are created, but do not fit existing capacity yet | Pending: “waiting for CapacityBuffers to fit existing capacity” |
| Every CapacityBuffer fits existing capacity | Ready: “CapacityBuffers fit existing capacity” |
| No PodSet requests a managed resource | Ready: “the workload has no podsets requesting managed resources” |
timeoutSeconds passes before the CapacityBuffers fit | Retry: “CapacityBuffers did not fit existing capacity within <n>s” |
| A CapacityBuffer with Kueue’s name is not owned by the Workload | Pending: “CapacityBuffer <name> already exists and is not owned by the workload”, and a FailedCreate event |
| The CapacityBufferConfig is missing | Pending: “the check is not active”, and the ClusterQueue is inactive |
| The check is added to the ClusterQueue of an admitted Workload | Ready: “the workload was admitted before the check was added” |
Once the check is Ready, Kueue does not check the CapacityBuffers’ condition again.
If the CapacityBufferConfig is deleted, admitted Workloads keep running and their checks stay Ready.
Topology-Aware Scheduling
With Topology-Aware Scheduling, Kueue assigns the topology after the check is Ready,
using the nodes that the autoscaler provisioned, as it does for ProvisioningRequest.
The CapacityBuffer does not carry the topology request, so a required topology is satisfied only if the autoscaler provisions the capacity in one topology domain.
timeoutSeconds also limits the wait for the topology assignment, measured from the time the check became Ready.
Set timeoutSeconds on configs that Topology-Aware Scheduling flavors use. Without it, a Workload whose topology never fits keeps its quota and its CapacityBuffers.
Limitations
The CapacityBuffer admission check is alpha. In this version:
- Cluster Autoscaler also implements CapacityBuffers, but it reports a different condition, so the check does not become
Readywith it yet. - MultiKueue, ConcurrentAdmission, and elastic Jobs are not supported.
- DynamicResourceAllocation and PersistentVolumeClaims are not supported: the autoscaler does not consider the ResourceClaims or volumes of the Pod template.
- The autoscaler can report
FitsExistingCapacityfor nodes that are launched but not ready yet, so the Pods can still wait for their nodes to start. - After Kueue deletes a CapacityBuffer, the autoscaler can remove its nodes until the Pods are bound to them.
With Karpenter, set the NodePool’s
consolidateAfterto a value that covers the time until the Workload’s Pods are bound. - If the Workload’s Pods are never all created, for example because a namespace ResourceQuota allows only some of them,
the created Pods stay gated and the CapacityBuffer keeps its nodes.
waitForPodsReady, which is enabled by default with a 30 minute timeout, evicts such a Workload and deletes its CapacityBuffers.
Before you disable the CapacityBufferACC feature gate, remove the CapacityBuffer admission checks from your ClusterQueues.
With the gate disabled, Kueue does not run the CapacityBuffer controller, so it neither updates these checks nor removes the
kueue.x-k8s.io/capacity-buffer scheduling gate from Pods. Remove the gate from such Pods by hand.
Example
Setup
apiVersion: kueue.x-k8s.io/v1beta2
kind: ResourceFlavor
metadata:
name: "gpu-flavor"
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: ClusterQueue
metadata:
name: "cluster-queue"
spec:
namespaceSelector: {} # match all.
resourceGroups:
- coveredResources: ["cpu", "memory", "nvidia.com/gpu"]
flavors:
- name: "gpu-flavor"
resources:
- name: "cpu"
nominalQuota: 32
- name: "memory"
nominalQuota: 128Gi
- name: "nvidia.com/gpu"
nominalQuota: 8
admissionChecksStrategy:
admissionChecks:
- name: "sample-capacity-buffer"
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: LocalQueue
metadata:
namespace: "default"
name: "user-queue"
spec:
clusterQueue: "cluster-queue"
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: AdmissionCheck
metadata:
name: sample-capacity-buffer
spec:
controllerName: kueue.x-k8s.io/capacity-buffer
parameters:
apiGroup: kueue.x-k8s.io
kind: CapacityBufferConfig
name: capacity-buffer-config
---
apiVersion: kueue.x-k8s.io/v1alpha1
kind: CapacityBufferConfig
metadata:
name: capacity-buffer-config
spec:
managedResources:
- nvidia.com/gpu
timeoutSeconds: 600
retryStrategy:
backoffBaseSeconds: 60
backoffMaxSeconds: 1800
Job using a CapacityBuffer
apiVersion: batch/v1
kind: Job
metadata:
generateName: sample-job-
namespace: default
labels:
kueue.x-k8s.io/queue-name: user-queue
spec:
parallelism: 2
completions: 2
template:
spec:
tolerations:
- key: "nvidia.com/gpu"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: dummy-job
image: registry.k8s.io/e2e-test-images/agnhost:2.53
args: ["pause"]
resources:
requests:
cpu: "1"
memory: "1Gi"
nvidia.com/gpu: 1
limits:
nvidia.com/gpu: 1
restartPolicy: Never
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.