In Kueue 0.20, how do a ResourceFlavor, a ClusterQueue and a LocalQueue decide when a team's GPU job is admitted, and how does a cohort let it borrow?
answer
- admission, not pod placement
- a flavor maps quota to nodes
- nominalQuota per flavor and resource
- queue-name label to a LocalQueue
- cohortName, borrowingLimit, lendingLimit
basics
~20 sKueue admits whole jobs against quota: a ResourceFlavor names a class of nodes, a ClusterQueue holds nominalQuota per flavor and resource, and a LocalQueue routes a namespace's jobs to it. ClusterQueues sharing a cohortName can borrow each other's unused quota.
solid answer
~40 sA Job labelled `kueue.x-k8s.io/queue-name` is suspended by Kueue's webhook and represented by a `Workload`. The LocalQueue in that namespace points at a ClusterQueue, which tries its flavors in order and admits the Workload only when quota for all its pod sets fits; Kueue then injects the flavor's `nodeLabels`, resumes the Job, and kube-scheduler places the pods, since Kueue never binds pods itself. With `cohortName: gpu-pool`, a queue may exceed its `nominalQuota` by borrowing idle quota from cohort peers, up to `borrowingLimit` (null means no limit), while a lender keeps `nominalQuota` minus `lendingLimit` for itself. Two traps: `namespaceSelector` defaults to null, which admits no namespace, and taking lent quota back needs `preemption.reclaimWithinCohort`, whose default is `Never`.
code
yaml · 23 linesapiVersion: kueue.x-k8s.io/v1beta2
kind: ClusterQueue
metadata:
name: team-finetune
spec:
cohortName: gpu-pool
namespaceSelector:
matchLabels:
team: finetune
resourceGroups:
- coveredResources: ["cpu", "memory", "nvidia.com/gpu"]
flavors:
- name: h100-80gb
resources:
- {name: cpu, nominalQuota: 1024}
- {name: memory, nominalQuota: 8Ti}
- {name: nvidia.com/gpu, nominalQuota: 64, borrowingLimit: 32}
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: LocalQueue
metadata: {namespace: finetune, name: finetune-queue}
spec:
clusterQueue: team-finetunego deeper
Recall the chain: a Job with a queue-name label, a LocalQueue, a ClusterQueue holding quota, a ResourceFlavor for the nodes, and that Kueue admits while kube-scheduler places.
Explain whole-Workload admission, flavor order, nominalQuota, borrowingLimit and lendingLimit, and compute the most a queue can hold inside its cohort.
Spot the operational traps: a null namespaceSelector, reclaimWithinCohort left at Never, and borrowed capacity that only preemption, costing someone a restart, can take back.
Design the split across teams: guaranteed versus lendable share, who may preempt whom inside the cohort, and how that reflects each group's business priority.
## What Kueue decides **Kueue** manages quotas and how jobs consume them: it decides when a job waits, when it is **admitted** (its pods may be created) and when it is preempted. It does not replace any Kubernetes component. Placing pods on nodes stays with kube-scheduler and running Jobs stays with the job controller. That split matters on a shared GPU cluster: Kueue answers "may this team start this job now?", and kube-scheduler answers "which node does each pod go to?". ## The four objects (API `kueue.x-k8s.io/v1beta2`) | Object | Scope | Key fields | Role | |---|---|---|---| | `ResourceFlavor` | cluster | `nodeLabels`, `nodeTaints`, `tolerations`, `topologyName` | A class of nodes, e.g. `h100-80gb` matched on `nvidia.com/gpu.product` | | `ClusterQueue` | cluster | `resourceGroups` (`coveredResources`, `flavors[].resources[].nominalQuota` / `borrowingLimit` / `lendingLimit`), `namespaceSelector`, `cohortName`, `queueingStrategy`, `preemption` | The quota pool and its admission policy | | `LocalQueue` | namespace | `clusterQueue` | What users submit to | | `Workload` | namespace | pod sets with counts and requests | The unit of admission, created by Kueue for each job | ## One job's path 1. A user creates a Job (or a JobSet, RayJob, Kubeflow job and so on) with the label `kueue.x-k8s.io/queue-name: finetune-queue`. It does not need to be created suspended; Kueue's webhook manages that. 2. Kueue creates a **Workload** whose usage is each pod set's requests multiplied by its pod count. 3. The ClusterQueue checks `namespaceSelector`, then walks its flavors in order and picks the first one in which the pod sets fit. 4. **Admission reserves quota for the whole Workload at once**; Kueue does not admit a fraction of it unless partial admission is explicitly enabled. 5. Kueue injects the flavor's `nodeLabels` (and `tolerations`) into the pods and resumes the Job; kube-scheduler places the pods. The default `queueingStrategy` is `BestEffortFIFO`: an older Workload that cannot fit does not block a newer one that does. `StrictFIFO` makes it block. ## Several flavors in one queue A ClusterQueue can list more than one flavor for the same resource, for instance `h100-80gb` first and an older GPU flavor second. Kueue tries them in list order, and `flavorFungibility` decides when it moves on: - `whenCanBorrow` defaults to `MayStopSearch`: if a Workload fits the first flavor **by borrowing**, Kueue stops there rather than trying the second flavor's free nominal quota. Set `TryNextFlavor` when owned capacity elsewhere should win over borrowing. - `whenCanPreempt` defaults to `TryNextFlavor`: if fitting the first flavor would need preemption, Kueue looks at the next flavor first. - Each pod set resource is assigned one flavor; a Workload's pod sets do not straddle two flavors for the same resource. ## Borrowing inside a cohort ClusterQueues with the same `cohortName` form a **cohort** and may borrow each other's unused quota. A pod set fits a flavor when its requests fit the queue's unused `nominalQuota`, or fit both the cohort's unused nominal quota and the queue's unused `nominalQuota + borrowingLimit`; the second case is **borrowing**. A queue borrows only for flavors it defines, and Kueue prefers workloads that fit under nominal quota over borrowers. Take `team-pretrain` with 160 GPUs of `h100-80gb` and `team-finetune` with 64, both in cohort `gpu-pool`, while pretraining is idle: - `team-finetune` with `borrowingLimit: 32` can hold at most 64 + 32 = **96** GPUs. - With `borrowingLimit` null it could reach 64 + 160 = **224**. - If `team-pretrain` sets `lendingLimit: 96`, it keeps 160 - 96 = **64** GPUs that are never lent. ## Getting lent quota back `preemption.reclaimWithinCohort` on the lender's ClusterQueue decides whether its pending Workload, fitting its own nominal quota, may preempt borrowers: `Never` (the default) waits for them to finish, `LowerPriority` preempts only lower-priority borrowers, `Any` preempts borrowers regardless of priority. A preempted Workload is evicted, its Job suspended and requeued; picking up training again from a checkpoint is the job's own business. ## Release traps in Kueue 0.20 - `v1beta2` is the storage version, and the cohort field is **`cohortName`**; `v1beta1` called it `cohort`. - `namespaceSelector` **null matches no namespace**; `{}` matches all of them. A ClusterQueue created without it admits nothing. - Kueue counts **requests**: a pod that sets only limits is counted at its limits, and a Workload's usage is per-pod requests times the pod count, so a 4-pod job of 8 GPUs each needs 32 GPUs of free quota before any pod starts. - List every resource the pods request, GPUs, CPU and memory, in `coveredResources`, as in the example; resources Kueue should ignore are named in its configuration's `excludeResourcePrefixes`.
- What does lendingLimit add on a Kueue ClusterQueue that lends quota?It caps how much of the queue's unused nominal quota cohort peers may borrow, so the queue keeps `nominalQuota` minus `lendingLimit` for itself. With `team-pretrain` at 160 GPUs and `lendingLimit: 96`, 64 GPUs are never lent, so a small pretraining job never waits behind borrowers. Null lets everything be lent.
- How does the pretraining team get back GPUs its Kueue ClusterQueue lent to a cohort peer?Set `preemption.reclaimWithinCohort` on its ClusterQueue: `LowerPriority` preempts lower-priority borrowers, `Any` preempts borrowers regardless of priority, and the default `Never` waits until they finish. Kueue evicts a preempted Workload by suspending its Job and requeueing it, so the evicted training job must resume from its own checkpoint.
- Kueue replaces kube-scheduler and binds pods to nodes itself.
- A ClusterQueue without a namespaceSelector accepts every namespace.
- A null borrowingLimit means the queue cannot borrow at all.
- Lent quota comes back automatically the moment the lender submits a job.
- Kueue admits a job pod by pod as each pod's share of quota frees up.
Assumes Kueue 0.20 with the kueue.x-k8s.io/v1beta2 API as storage version, where the ClusterQueue cohort field is cohortName (v1beta1 called it cohort).