Kueue Concept#
Versions used: Kubernetes
v1.35.8(GKE Standard), Kueuev0.20.5
Kueue is a Kubernetes-native job queueing system that decides whether a Job may start now.
Why It Exists#
kube-scheduler only decides which node a single Pod goes to. When resources run out, Pods pile up as Pending, and these questions stay unanswered:
- In what order do Jobs over the limit wait, and who starts first when room opens up?
- May one team borrow another team’s unused share?
- Who gets evicted when an urgent Job arrives?
Kueue answers them with per-Job quota and queues.
How It Differs from ResourceQuota#
A per-team limit by itself can be set with ResourceQuota. (For example requests.nvidia.com/gpu) The difference is what happens when the limit is exceeded.
ResourceQuota | Kueue | |
|---|---|---|
| Unit | Namespace | Submitted through a namespaced LocalQueue, limited by a ClusterQueue. LocalQueues in several namespaces may point to one ClusterQueue |
| Over the limit | Pod creation is rejected. The Job controller retries with backoff | The Job waits in a queue, suspended |
| Ordering | None. Whichever retry succeeds first wins | Priority and arrival order |
| Partially running Job | Possible. Only some Pods may be created | No. A Job is admitted only when all of it fits |
| Borrowing unused share | No | Yes, with Cohort |
| Preemption | No | Yes |
| Limits per node type | No | Yes, with ResourceFlavor |
How It Works#
Kueue does not replace the scheduler. It gates Jobs in front of it.
- When a Job is created, a mutating webhook sets
job.spec.suspendtotrue. No Pods are created yet. - The Pod run by the
kueue-controller-managerDeployment in thekueue-systemnamespace creates a matchingWorkloadobject and puts it in a queue. - When quota frees up, the same Pod admits the Job and sets
job.spec.suspendtofalse. - Pods are created, and
kube-schedulerplaces them on nodes.
Installed Components#
Installing is a single manifests.yaml, with no change to the control plane or nodes. It is not CRDs only, though.
| Component | Role |
|---|---|
| 11 CRDs | API definitions |
kueue-controller-manager (Deployment) | Queueing and admission logic |
| Admission webhooks | Set job.spec.suspend on Job creation, validate objects |
APIService | Visibility API for queue positions |
- The controller, webhook server, and visibility API server all run in the same Pod on different ports.
- Webhooks use
failurePolicy: Fail. If the controller Pod cannot start, Job creation itself fails. - Kueue manages only Jobs labeled
kueue.x-k8s.io/queue-name. (Default configuration)
All Three Services Point to the Same Pod#
The three Services in kueue-system have the same Endpoint IP. They all point to the single Pod created by the kueue-controller-manager Deployment, on different ports.
$ kubectl describe svc -n kueue-system | grep $(kubectl get pods -n kueue-system $POD_NAME -o json | jq '.status.podIP' -r)
Endpoints: 10.21.2.6:8443
Endpoints: 10.21.2.6:8082
Endpoints: 10.21.2.6:9443
| Port | Service | Purpose |
|---|---|---|
9443 | kueue-webhook-service | Admission webhooks |
8082 | kueue-visibility-server | Visibility API (aggregated API) |
8443 | kueue-controller-manager-metrics-service | Metrics |
Where job.spec.suspend Is Set#
manifests.yaml contains no suspend: true. The MutatingWebhookConfiguration only declares when and where to call.
- name: mjob.kb.io
clientConfig:
service:
name: kueue-webhook-service
namespace: kueue-system
path: /mutate-batch-v1-job # Called when a batch/v1 Job is CREATEdWhat to change lives in the controller’s Go code that serves that path. The call chain is:
JobWebhook.Default(): handles the/mutate-batch-v1-jobrequest.ApplyDefaultForSuspend(): callsjob.Suspend()if Kueue should manage the Job and it is not suspended yet.Job.Suspend(): setsjob.spec.suspendtotrue.
// pkg/controller/jobs/job/job_controller.go
func (j *Job) Suspend() {
j.Spec.Suspend = new(true)
}Webhooks and APIService#
Both the webhooks and the APIService are registered as objects, with no API server flags. See API Extension for how they work in general.
Why Only Visibility Is Not a CRD#
A queue position is computed from the queue state in the controller’s memory. Putting it in a CRD status would cost an etcd write every time positions shift, so Kueue serves it from memory through an aggregated API.
Queueing itself runs in memory regardless of the visibility API. The source of truth is the Workload objects in etcd; the controller watches them and builds the queues in memory. After a controller restart, the queues are rebuilt from the Workload objects.
CRDs#
Core Four#
| CRD | Scope | Created by | Role |
|---|---|---|---|
ResourceFlavor | Cluster | Cluster admin | A kind of resource, mapped to node labels and taints |
ClusterQueue | Cluster | Cluster admin | The quota pool, with a nominalQuota per flavor. Quota is allocated here |
LocalQueue | Namespaced | Admin | A namespaced entrance into a ClusterQueue. It has no quota of its own |
Workload | Namespaced | kueue-controller-manager | One Job’s resource request and admission state. Created automatically when a Job is created |
With the RBAC that Kueue installs by default, only kueue-batch-admin-role can create ResourceFlavor, ClusterQueue, and LocalQueue. kueue-batch-user-role can only view LocalQueue and Workload. Letting namespace admins create LocalQueues requires granting that permission separately.
From Job to Quota#
Job ──(queue-name label)──▶ LocalQueue ──(spec.clusterQueue)──▶ ClusterQueue ──(flavors)──▶ ResourceFlavor
│ ▲
└── Workload (auto-created in the Job's namespace) ── consumes quota when admitted ──┘- The Job’s
kueue.x-k8s.io/queue-namelabel selects theLocalQueue. - The
LocalQueue’sspec.clusterQueueselects theClusterQueuethat provides quota. - When the
Workloadis admitted, its request is deducted from thatClusterQueue’s quota and returned when it finishes. - If quota is short, the
Workloadwaits and the Job stays atjob.spec.suspend: true.
What shares the quota is not Jobs or LocalQueues but the admitted Workloads.
Seven Optional Ones#
| CRD | Role |
|---|---|
Cohort | Groups ClusterQueues so they can borrow unused quota |
WorkloadPriorityClass | Ordering and preemption priority within queues |
AdmissionCheck | Extra conditions to pass besides quota |
ProvisioningRequestConfig | Asks the autoscaler to secure nodes before admission |
MultiKueueCluster | Connection details for one worker cluster |
MultiKueueConfig | The set of worker clusters a Job may be sent to |
Topology | Defines block, rack, and host levels from node labels |
A ResourceFlavor Is a Ledger Entry and a Routing Rule#
A Job admitted with a flavor gets the flavor’s nodeLabels injected as nodeSelector and its tolerations injected as tolerations in the Pod template. The Job author writes neither, and the Pods still land only on those nodes.
# An empty spec means "any node". Enough when there is only one kind of node.
apiVersion: kueue.x-k8s.io/v1beta2
kind: ResourceFlavor
metadata:
name: default-flavor
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: ResourceFlavor
metadata:
name: l4-gpu
spec:
nodeLabels:
# Assumes GKE Standard with a node pool named gpu-pool
cloud.google.com/gke-nodepool: gpu-pool
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoScheduleQuota Lives Only in ClusterQueue#
ClusterQueue: the actual quota pool.LocalQueue: an entrance with no limit of its own.
LocalQueues that point to the same ClusterQueue do not split it. They compete for one pool.
apiVersion: kueue.x-k8s.io/v1beta2
kind: ClusterQueue
metadata:
name: demo-cq
spec:
namespaceSelector: {}
resourceGroups:
- coveredResources: ["cpu", "memory"]
flavors:
- name: default-flavor # The ResourceFlavor this quota applies to
resources:
- name: cpu
nominalQuota: 1
- name: memory
nominalQuota: 1Gi
- coveredResources: ["nvidia.com/gpu"]
flavors:
- name: l4-gpu # The ResourceFlavor this quota applies to
resources:
- name: nvidia.com/gpu
nominalQuota: 1
---
apiVersion: kueue.x-k8s.io/v1beta2
kind: LocalQueue
metadata:
namespace: kueue-demo
name: team-a
spec:
clusterQueue: demo-cq| Goal | Setup |
|---|---|
| Guaranteed quota per team | One ClusterQueue per team |
| Borrowing unused share | Put those ClusterQueues in the same Cohort |
LocalQueue exists not to divide quota but to let ordinary users reach a cluster-scoped ClusterQueue with namespace-level permissions.