Day 10: Kueue I – GPU Quotas per Team
Goal: Three AI teams get fixed GPU quotas. Jobs wait in a queue instead of clogging the scheduler as Pending Pods, and Kueue admits them only when the quota is sufficient. You also see how to get around Kueue and how to recognize a job that will never start · Duration: approx. 75 min · Prerequisite: Day 8
Briefing
- Without Kueue, the scheduler decides on a “first come, first served” basis. One team submits 20 training jobs, and the other teams see nothing but Pending Pods for days.
- Kueue is a Kubernetes SIG project that works
before the scheduler. A job arrives with
suspend: true, Kueue checks its team’s quota, and only when it is sufficient does Kueue admit it (admission) and setsuspend: false. Only then are Pods created. - The building blocks:
| Object | Scope | Purpose |
|---|---|---|
| ResourceFlavor | Cluster | a kind of node, here “A100 nodes”, with labels and tolerations |
| ClusterQueue | Cluster | a team’s quota (nominalQuota) per flavor and resource |
| LocalQueue | Namespace | a team’s mailbox, points to a ClusterQueue |
| Workload | Namespace | Kueue’s view of a job: what it needs, whether it is admitted |
- Everything about Kueue is real. The GPUs still come via DRA from Day
8: jobs write
nvidia.com/gpu, andextendedResourceNameturns that into claims.
Job (queue-name: gpu, suspend) ──▶ LocalQueue gpu ──▶ ClusterQueue training (4 GPUs)
│ is the quota sufficient?
yes: admission, suspend=false, flavor sets nodeSelector + toleration ──▶ Pods
no: waits as a Workload, no Pods
The three teams: training (4 GPUs),
inferenz (2) and forschung (2). Together, the
8 GPUs of the node.
Drill 1: Installing Kueue
mkdir -p ~/gpu/tag10 && cd ~/gpu/tag10
helm install kueue oci://registry.k8s.io/kueue/charts/kueue --version 0.20.7 -n kueue-system --create-namespace --wait --timeout 300s | tail -3
kubectl -n kueue-system get pods
kubectl api-resources --api-group=kueue.x-k8s.io | awk '{print $1}'Expected:
REVISION: 1
DESCRIPTION: Install complete
TEST SUITE: None
NAME READY STATUS RESTARTS AGE
kueue-controller-manager-5cbdc846d6-zfrdt 1/1 Running 0 26s
NAME
admissionchecks
clusterqueues
cohorts
localqueues
multikueueclusters
multikueueconfigs
provisioningrequestconfigs
resourceflavors
topologies
workloadpriorityclasses
workloads
One controller and eleven custom resources, all in API version
v1beta2 (kubectl api-resources without
awk shows them). Today you need four of them.
Save your progress? Sign up for free
Drill 2: Flavor, ClusterQueue, LocalQueue
The ResourceFlavor describes the A100 nodes via the GFD label from Day 3 and the toleration for the taint from Day 4. Kueue later inserts both into every admitted Pod:
cd ~/gpu/tag10
cat > flavor.yaml <<'EOF'
apiVersion: kueue.x-k8s.io/v1beta2
kind: ResourceFlavor
metadata:
name: a100
spec:
nodeLabels:
nvidia.com/gpu.product: NVIDIA-A100-SXM4-40GB
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoSchedule
EOF
cat > cq-training.yaml <<'EOF'
apiVersion: kueue.x-k8s.io/v1beta2
kind: ClusterQueue
metadata:
name: training
spec:
namespaceSelector: {}
resourceGroups:
- coveredResources: ["cpu", "memory", "nvidia.com/gpu"]
flavors:
- name: a100
resources:
- name: cpu
nominalQuota: 4
- name: memory
nominalQuota: 8Gi
- name: nvidia.com/gpu
nominalQuota: 4
EOF
kubectl create ns training
cat > lq-training.yaml <<'EOF'
apiVersion: kueue.x-k8s.io/v1beta2
kind: LocalQueue
metadata:
name: gpu
namespace: training
spec:
clusterQueue: training
EOF
kubectl apply -f flavor.yaml -f cq-training.yaml -f lq-training.yaml
kubectl get cq
kubectl -n training get lqExpected:
namespace/training created
resourceflavor.kueue.x-k8s.io/a100 created
clusterqueue.kueue.x-k8s.io/training created
localqueue.kueue.x-k8s.io/gpu created
NAME COHORT PENDING WORKLOADS
training 0
NAME CLUSTERQUEUE PENDING WORKLOADS ADMITTED WORKLOADS
gpu training 0 0
coveredResources lists what this queue watches over. A
job that requests one of these resources must fit into the quota.
namespaceSelector: {} allows LocalQueues from all
namespaces; in production you restrict this to the team’s
namespaces.
Save your progress? Sign up for free
Drill 3: The First Job
A job registers with its LocalQueue via the label
kueue.x-k8s.io/queue-name. It requests 2 GPUs, some CPU and
memory, and has neither a toleration nor a nodeSelector:
cd ~/gpu/tag10
cat > job.yaml <<'EOF'
apiVersion: batch/v1
kind: Job
metadata:
name: lauf-1
namespace: training
labels:
kueue.x-k8s.io/queue-name: gpu
spec:
parallelism: 1
completions: 1
template:
spec:
restartPolicy: Never
containers:
- name: train
image: ubuntu:24.04
command: ["sh", "-c", "nvidia-smi -L; sleep 600"]
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
nvidia.com/gpu: 2
EOF
kubectl apply -f job.yaml
sleep 8
kubectl -n training get workloads
kubectl -n training get pods -o wide
kubectl -n training logs job/lauf-1
kubectl -n training get pod -l job-name=lauf-1 -o jsonpath='{.items[0].spec.nodeSelector}{"\n"}'Expected:
job.batch/lauf-1 created
NAME QUEUE RESERVED IN ADMITTED FINISHED AGE
job-lauf-1-fbc79 gpu training True 8s
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
lauf-1-9kdzh 1/1 Running 0 8s 10.244.2.115 gpu-worker2 <none> <none>
GPU 0: NVIDIA A100-SXM4-40GB (UUID: GPU-12345678-1234-1234-1234-123456780002)
GPU 1: NVIDIA A100-SXM4-40GB (UUID: GPU-12345678-1234-1234-1234-123456780003)
{"nvidia.com/gpu.product":"NVIDIA-A100-SXM4-40GB"}
Kueue created a Workload for the job, reserved it in
the training quota and admitted it. The Pod runs on the GPU
node, even though the job has no toleration and no nodeSelector: Kueue
inserted both from the flavor. The two GPUs are allocated by the DRA
driver, as on Day 8.
Save your progress? Sign up for free
Drill 4: The Quota Is Full
Two more jobs with 2 GPUs each. The quota of 4 is enough for two jobs, not for three:
cd ~/gpu/tag10
for n in 2 3; do sed "s/name: lauf-1/name: lauf-$n/" job.yaml | kubectl apply -f -; done
sleep 8
kubectl -n training get jobs
kubectl -n training get pods
kubectl -n training get workloads
kubectl -n training get job lauf-3 -o jsonpath='{.spec.suspend}{"\n"}'Expected:
job.batch/lauf-2 created
job.batch/lauf-3 created
NAME STATUS COMPLETIONS DURATION AGE
lauf-1 Running 0/1 27s 27s
lauf-2 Running 0/1 8s 9s
lauf-3 Suspended 0/1 8s
NAME READY STATUS RESTARTS AGE
lauf-1-9kdzh 1/1 Running 0 28s
lauf-2-bjq4b 1/1 Running 0 9s
NAME QUEUE RESERVED IN ADMITTED FINISHED AGE
job-lauf-1-fbc79 gpu training True 28s
job-lauf-2-e4744 gpu training True 9s
job-lauf-3-9265e gpu False 9s
true
lauf-3 is suspended, and there is no
Pod for it. That is the difference from Day 4: there, Pending Pods sat
with the scheduler, which re-checked them on every pass. Here, only a
Workload waits in Kueue. Why is written in its conditions:
w=$(kubectl -n training get workloads -o name | grep lauf-3)
kubectl -n training get $w -o jsonpath='{range .status.conditions[*]}{.type}: {.message}{"\n"}{end}'
kubectl get cq training -o jsonpath='{range .status.flavorsUsage[0].resources[*]}{.name}={.total} {end}{"\n"}'
kubectl -n training get lqExpected:
QuotaReserved: couldn't assign flavors to pod set main: insufficient unused quota for nvidia.com/gpu in flavor a100, 2 more needed
Admitted: The workload has no reservation
PodsReady: Not all pods are ready or succeeded
cpu=1 memory=1Gi nvidia.com/gpu=4
and the LocalQueue with 1 pending and 2
admitted workloads. “2 more needed”: the job would need two more GPUs.
When a job finishes or is deleted, the next one moves up:
kubectl -n training delete job lauf-1
sleep 6
kubectl -n training get jobsExpected:
job.batch "lauf-1" deleted from training namespace
NAME STATUS COMPLETIONS DURATION AGE
lauf-2 Running 0/1 37s 38s
lauf-3 Running 0/1 5s 37s
Save your progress? Sign up for free
Drill 5: Getting Around Kueue
What happens to a job without the queue-name label? A
colleague copies the job, leaves out the label and sets the toleration
themselves:
cd ~/gpu/tag10
sed -e 's/name: lauf-1/name: schwarz/' -e '/kueue.x-k8s.io\/queue-name/d' -e '/^ labels:/d' job.yaml > job-ohne.yaml
sed -i 's/ restartPolicy: Never/ restartPolicy: Never\n tolerations:\n - key: nvidia.com\/gpu\n operator: Exists\n effect: NoSchedule/' job-ohne.yaml
grep -c queue-name job-ohne.yaml
kubectl apply -f job-ohne.yaml
sleep 8
kubectl -n training get pods -l job-name=schwarz -o wide
kubectl -n training get workloads | grep -c schwarz
kubectl get cq training -o jsonpath='{range .status.flavorsUsage[0].resources[*]}{.name}={.total} {end}{"\n"}'
kubectl -n training delete job schwarzExpected:
0
job.batch/schwarz created
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
schwarz-8n9qk 1/1 Running 0 9s 10.244.2.118 gpu-worker2 <none> <none>
0
cpu=1 memory=1Gi nvidia.com/gpu=4
job.batch "schwarz" deleted from training namespace
The job runs on two GPUs, without a Workload, without the
ClusterQueue knowing anything about it: it still counts 4. By default,
Kueue only manages jobs with a queue label. If you don’t want that, you
enable manageJobsWithoutQueueName: true in the Kueue
configuration, so that Kueue suspends every job without a label, or you
forbid jobs without a label via an admission policy (Kyverno or
ValidatingAdmissionPolicy). Without one of these two measures, quotas
are a request, not a rule.
Tried it: Without the self-set toleration, the Pod stayed
Pending, but not because of Kueue, rather because of the taint from Day 4. A taint on GPU nodes makes sneaking past less convenient, but does not prevent it.
Save your progress? Sign up for free
Drill 6: Three Teams
The ClusterQueues for inferenz and
forschung are derived from the one for
training, with half the quota:
cd ~/gpu/tag10
for t in inferenz forschung; do
sed -e "s/name: training/name: $t/" -e 's/nominalQuota: 4$/nominalQuota: 2/' -e 's/nominalQuota: 8Gi/nominalQuota: 4Gi/' cq-training.yaml > cq-$t.yaml
kubectl create ns $t
sed -e "s/namespace: training/namespace: $t/" -e "s/clusterQueue: training/clusterQueue: $t/" lq-training.yaml > lq-$t.yaml
kubectl apply -f cq-$t.yaml -f lq-$t.yaml
done
kubectl get cqExpected:
namespace/inferenz created
clusterqueue.kueue.x-k8s.io/inferenz created
localqueue.kueue.x-k8s.io/gpu created
namespace/forschung created
clusterqueue.kueue.x-k8s.io/forschung created
localqueue.kueue.x-k8s.io/gpu created
NAME COHORT PENDING WORKLOADS
forschung 0
inferenz 0
training 0
The research team submits two experiments with 2 GPUs each:
for n in 1 2; do sed -e "s/name: lauf-1/name: experiment-$n/" -e 's/namespace: training/namespace: forschung/' job.yaml | kubectl apply -f -; done
sleep 8
kubectl -n forschung get jobs
kubectl get resourceclaim -A -o json | jq '[.items[].status.allocation.devices.results[]] | length'
kubectl get cq -o custom-columns=NAME:.metadata.name,GPU-QUOTE:.spec.resourceGroups[0].flavors[0].resources[2].nominalQuota,GPU-BELEGT:.status.flavorsUsage[0].resources[2].total,WARTEND:.status.pendingWorkloadsExpected:
job.batch/experiment-1 created
job.batch/experiment-2 created
NAME STATUS COMPLETIONS DURATION AGE
experiment-1 Running 0/1 8s 8s
experiment-2 Suspended 0/1 8s
6
NAME GPU-QUOTE GPU-BELEGT WARTEND
forschung 2 2 1
inferenz 2 0 0
training 4 4 0
Six of eight GPUs are occupied, two are free. Still,
experiment-2 waits, because the research quota is
exhausted, and the two free GPUs belong to the quota of
inferenz, which nobody is using right now. Fixed quotas are
fair, but wasteful. How teams borrow unused GPUs and give them back is
Day 11.
Save your progress? Sign up for free
Exercise: Speed Drills
- How many workloads are admitted in
training? Just the number. Target time: 30 s - Which nodeSelector did Kueue set in the Pods of
lauf-2? Target time: 30 s - Why is
experiment-2waiting? The message from the Workload. Target time: 45 s
Solution
kubectl -n training get workloads --no-headers | awk '$4 == "True"' | wc -l
kubectl -n training get pod -l job-name=lauf-2 -o jsonpath='{.items[0].spec.nodeSelector}{"\n"}'
w=$(kubectl -n forschung get workloads -o name | grep experiment-2)
kubectl -n forschung get $w -o jsonpath='{range .status.conditions[?(@.type=="QuotaReserved")]}{.message}{"\n"}{end}'Expected:
2
{"nvidia.com/gpu.product":"NVIDIA-A100-SXM4-40GB"}
couldn't assign flavors to pod set main: insufficient unused quota for nvidia.com/gpu in flavor a100, 2 more needed
Save your progress? Sign up for free
Challenge
The training team submits a big run:
cd ~/gpu/tag10
sed -e 's/name: lauf-1/name: riesig/' -e 's/nvidia.com\/gpu: 2/nvidia.com\/gpu: 5/' job.yaml | kubectl apply -f -
sleep 6
kubectl -n training get job riesigExpected:
job.batch/riesig created
NAME STATUS COMPLETIONS DURATION AGE
riesig Suspended 0/1 6s
The team asks: “When will it start? We’ll wait until lauf-2 and lauf-3 are done.” Is that right? Back it up with Kueue’s message and propose a solution.
Hint: Compare the message with the one for
lauf-3 from Drill 4. One word makes the difference.
Solution
w=$(kubectl -n training get workloads -o name | grep riesig)
kubectl -n training get $w -o jsonpath='{range .status.conditions[?(@.type=="QuotaReserved")]}{.message}{"\n"}{end}'Expected:
couldn't assign flavors to pod set main: insufficient quota for nvidia.com/gpu in flavor a100, previously considered podsets requests (0) + current podset request (5) > maximum capacity (4)
For lauf-3 it said insufficient unused
quota: the quota is basically sufficient but currently
occupied; the job waits and gets its turn. Here it says
insufficient quota with
> maximum capacity (4): 5 GPUs never fit into a quota of
4. The job waits forever, even when all others are done. Solutions:
split the job into at most 4 GPUs (two Pods with
parallelism: 2 and 2 GPUs each), raise the quota, or borrow
GPUs from other teams (Day 11). With 4 GPUs it queues up correctly:
sed -e 's/name: lauf-1/name: riesig/' -e 's/nvidia.com\/gpu: 2/nvidia.com\/gpu: 4/' job.yaml > riesig.yaml
kubectl -n training delete job riesig
kubectl apply -f riesig.yaml
sleep 4
w=$(kubectl -n training get workloads -o name | grep riesig)
kubectl -n training get $w -o jsonpath='{range .status.conditions[?(@.type=="QuotaReserved")]}{.message}{"\n"}{end}'Expected:
job.batch "riesig" deleted from training namespace
job.batch/riesig created
couldn't assign flavors to pod set main: insufficient unused quota for nvidia.com/gpu in flavor a100, 4 more needed
Now it waits for free GPUs in its own quota, not for a miracle.
Save your progress? Sign up for free
Checkpoint
kubectl get rf a100 -o name
kubectl get cq -o custom-columns=NAME:.metadata.name,GPU:.spec.resourceGroups[0].flavors[0].resources[2].nominalQuota
for t in training inferenz forschung; do kubectl -n $t get lq gpu -o jsonpath='{.metadata.namespace}/{.metadata.name} -> {.spec.clusterQueue}{"\n"}'; doneExpected:
resourceflavor.kueue.x-k8s.io/a100
NAME GPU
forschung 2
inferenz 2
training 4
training/gpu -> training
inferenz/gpu -> inferenz
forschung/gpu -> forschung
Clean-up
The jobs go; queues and flavor stay for Day 11:
for t in training inferenz forschung; do kubectl -n $t delete jobs --all; done
sleep 30
kubectl get workloads -A
kubectl get cqExpected:
job.batch "lauf-2" deleted from training namespace
job.batch "lauf-3" deleted from training namespace
job.batch "riesig" deleted from training namespace
No resources found
job.batch "experiment-1" deleted from forschung namespace
job.batch "experiment-2" deleted from forschung namespace
No resources found
No resources found
NAME COHORT PENDING WORKLOADS
forschung 0
inferenz 0
training 0
The first No resources found comes from
inferenz, which had no jobs, the second from
kubectl get workloads. The claims of the deleted Pods
disappear with them as soon as the Pods have terminated.
Interview Note
- What does Kueue do differently from the scheduler? Kueue decides whether a job may start (quota, order, fairness), the scheduler decides where its Pods run. Waiting jobs are suspended and create no Pending Pods.
- ClusterQueue or LocalQueue? The ClusterQueue holds the quota and belongs to the platform. The LocalQueue is the entry point in the team’s namespace and points to a ClusterQueue.
- How do you recognize a job that will never start? “insufficient quota … > maximum capacity” instead of “insufficient unused quota”: it needs more than the quota will ever provide.
Enterprise Note
- Quotas without enforcement are worthless: enable
manageJobsWithoutQueueNameor reject jobs without a queue label via an admission policy, otherwise anyone can bypass Kueue by deleting one line. - Restrict the
namespaceSelectorof every ClusterQueue to the team’s namespaces, and let only the platform create LocalQueues. Otherwise one team hooks into another team’s queue. - Besides
batch/Job, Kueue also knows JobSet, Kubeflow training jobs, RayJobs and plain Pods. For distributed training with several Pods, Kueue admits all Pods of a job together (gang scheduling), instead of letting half of them start and the rest wait.