Cheat Sheet - Linux: /linux/ - CLI: /linux/cli/ - locate vs type vs which vs whereis: /linux/cli/locate-vs-type-vs-which-vs-whereis/ - make: /linux/cli/make/ - awk: /linux/cli/awk/ - find: /linux/cli/find/ - grep: /linux/cli/grep/ - pgrep: /linux/cli/pgrep/ - ps: /linux/cli/ps/ - pstree: /linux/cli/pstree/ - trap: /linux/cli/trap/ - xargs: /linux/cli/xargs/ - Shell: /linux/shell/ - BASH_SOURCE: /linux/shell/bash-source/ - Redirection: /linux/shell/redirection/ - Special Variables: /linux/shell/special-variables/ - Scripting Tips: /linux/shell/script-tips/ - set -o vi: /linux/shell/bash-vi-mode/ - Shell Processing Order: /linux/shell/process-order/ - What are Interactive and Login Shells?: /linux/shell/interactive-login/ - Double Quote Expansion: /linux/shell/shell-expansion/ - System Programming: /linux/system-programming/ - File I/O: /linux/system-programming/file-io/ - Process: /linux/system-programming/process/ - Shared Libraries: /linux/system-programming/shared-libraries/ - Kernel: /linux/kernel/ - Go: /programming/go/ - Concurrency: /programming/go/concurrency/ - CSP (Communicating Sequential Processes) and Channels: /programming/go/concurrency/csp/ - Channel: /programming/go/concurrency/channel/ - Select: /programming/go/concurrency/select/ - sync: /programming/go/concurrency/sync/ - Concurrency Patterns: /programming/go/concurrency/patterns/ - Goroutines and the Go Runtime: /programming/go/concurrency/runtime/ - Standard Library: /programming/go/std/ - os: /programming/go/std/os/ - context: /programming/go/std/context/ - io: /programming/go/std/io/ - json: /programming/go/std/json/ - net/http: /programming/go/std/net-http/ - slog: /programming/go/std/slog/ - testing: /programming/go/std/testing/ - time: /programming/go/std/time/ - Ellipsis (...): /programming/go/ellipsis/ - error: /programming/go/error/ - Function: /programming/go/function/ - Go Tool: /programming/go/tool/ - Interface: /programming/go/interface/ - Map: /programming/go/map/ - Package and Module: /programming/go/package-module/ - Pointer: /programming/go/pointer/ - Slice: /programming/go/slice/ - String: /programming/go/string/ - Switch: /programming/go/switch/ - Comparison: /programming/go/comparison/ - defaultdict: /programming/python/collections/defaultdict/ - heapq: /programming/python/collections/heapq/ - @cache: /programming/python/cache/ - abc: /programming/python/abc/ - bisect: /programming/python/bisect/ - Type Hints: /programming/python/type-hints/ - Passing Mechanism: /programming/python/passing-mechanism/ - uv: /programming/python/uv/ - *args and **kwargs: /programming/python/args-kwargs/ - re: /programming/python/re/ - C: /programming/c/ - Pointers and Arrays: /programming/c/pointer/ - Syntax Basics: /programming/c/syntax-basics/ - static: /programming/c/static/ - Bit Manipulation: /programming/c/bit-manipulation/ - C vs C++: /programming/c/c-vs-cpp/ - stdatomic: /programming/c/stdatomic/ - C++: /programming/cpp/ - RAII (Resource Acquisition Is Initialization): /programming/cpp/raii/ - Copy Elision & Move Semantics: /programming/cpp/copy-elision-and-move-semantics/ - Most Vexing Parse & In-Class Initializer: /programming/cpp/most-vexing-parse/ - C++ Keywords Reference: /programming/cpp/keywords/ - C++ Primer: /programming/cpp/primer/ - Variables and Basic Types: /programming/cpp/primer/variables-and-basic-types/ - Expressions: /programming/cpp/primer/expressions/ - Type Conversions and Casts: /programming/cpp/primer/type-conversions-and-casts/ - Statements: /programming/cpp/primer/statements/ - Functions: /programming/cpp/primer/functions/ - Classes: /programming/cpp/primer/classes/ - The IO Library: /programming/cpp/primer/io-library/ - STL: /programming/cpp/primer/stl/ - Lambda Expressions: /programming/cpp/primer/lambda/ - Smart Pointers: /programming/cpp/primer/smart-pointers/ - Copy Control: /programming/cpp/primer/copy-control/ - Overloaded Operations and Conversions: /programming/cpp/primer/operator-overloading/ - Object-Oriented Programming (OOP): /programming/cpp/primer/oop/ - Templates and Generic Programming: /programming/cpp/primer/templates/ - Namespaces: /programming/cpp/primer/namespaces/ - Pointers to Class Member: /programming/cpp/primer/pointers-to-class-member/ - Advanced: /programming/cpp/advanced/ - Error Handling: /programming/cpp/advanced/error-handling/ - Concurrency & Threading: /programming/cpp/advanced/concurrency/ - Unit Testing: /programming/cpp/advanced/unit-testing/ - Comparison: /programming/comparison/ - Kubernetes: /cloud-devops/kubernetes/ - Fleet: /cloud-devops/kubernetes/gke/fleet/ - Kustomize vs Helm: /cloud-devops/kubernetes/kustomize-vs-helm/ - API Extension: /cloud-devops/kubernetes/api-extension/ - Concept: /cloud-devops/kubernetes/kueue/concept/ - DRA: /cloud-devops/kubernetes/dra/ - Secret Manager: /cloud-devops/terraform/google-secret-manager/ - Knowledge: /network/knowledge/ - PDU: /network/knowledge/osi-model/ - curl: /network/cli/curl/ - Concurrency Concepts: /cs/concurrency-and-parallelism/concepts/ - Concurrency vs Parallelism: /cs/concurrency-and-parallelism/concurrency-vs-parallelism/ - Mutex vs Atomic: /cs/concurrency-and-parallelism/mutex-vs-atomic/ - Regular Expression: /cs/regular-expression/ - Multiplexer vs Dispatcher: /cs/multiplexer-vs-dispatcher/ - Driver and Runtime: /ai-ml/gpu/driver-and-runtime/ - Serving: /ai-ml/serving/ - Dotfiles: /dotfiles/ - Git: /dotfiles/git/ - Cheat Sheet: /dotfiles/git/cheat-sheet/ - revisions: /dotfiles/git/revisions/ - Submodule vs Worktree: /dotfiles/git/submodule-vs-worktree/ - checkout, reset -> switch, restore: /dotfiles/git/checkout-switch-restore-reset/ - rebase: /dotfiles/git/rebase/ - Branching and Merging: /dotfiles/git/branching-merging/ - Vim: /dotfiles/vim/ - Plugin: /dotfiles/vim/plugin/ - auto-pairs: /dotfiles/vim/plugin/auto-pairs/ - vim-commentary: /dotfiles/vim/plugin/vim-commentary/ - vim-easymotion: /dotfiles/vim/plugin/vim-easymotion/ - vim-surround: /dotfiles/vim/plugin/vim-surround/ - Marks: /dotfiles/vim/tips/marks/ - vimrc: /dotfiles/vim/vimrc/ - lf: /dotfiles/lf/ # Kueue Concept > Versions used: Kubernetes `v1.35.8` (GKE Standard), Kueue `v0.20.5` [Kueue](https://kueue.sigs.k8s.io/) 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`. `LocalQueue`s 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. 1. When a Job is created, a [mutating webhook]({{< relref "/cloud-devops/kubernetes/api-extension.md#admission-webhook" >}}) sets `job.spec.suspend` to `true`. No Pods are created yet. 2. The Pod run by the `kueue-controller-manager` Deployment in the `kueue-system` namespace creates a matching `Workload` object and puts it in a queue. 3. When quota frees up, the same Pod admits the Job and sets `job.spec.suspend` to `false`. 4. Pods are created, and `kube-scheduler` places them on nodes. ## Installed Components Installing is a single [`manifests.yaml`](https://github.com/kubernetes-sigs/kueue/releases/download/v0.20.5/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 `Service`s 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. ```console $ 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. ```yaml - 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 CREATEd ``` What to change lives in the controller's Go code that serves that path. The call chain is: 1. [`JobWebhook.Default()`](https://github.com/kubernetes-sigs/kueue/blob/v0.20.5/pkg/controller/jobs/job/job_webhook.go#L102-L126): handles the `/mutate-batch-v1-job` request. 2. [`ApplyDefaultForSuspend()`](https://github.com/kubernetes-sigs/kueue/blob/v0.20.5/pkg/controller/jobframework/defaults.go#L35-L45): calls `job.Suspend()` if Kueue should manage the Job and it is not suspended yet. 3. [`Job.Suspend()`](https://github.com/kubernetes-sigs/kueue/blob/v0.20.5/pkg/controller/jobs/job/job_controller.go#L163-L165): sets `job.spec.suspend` to `true`. ```go // 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]({{< relref "/cloud-devops/kubernetes/api-extension.md" >}}) 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 `LocalQueue`s requires granting that permission separately. ### From Job to Quota ```text Job ──(queue-name label)──▶ LocalQueue ──(spec.clusterQueue)──▶ ClusterQueue ──(flavors)──▶ ResourceFlavor │ ▲ └── Workload (auto-created in the Job's namespace) ── consumes quota when admitted ──┘ ``` 1. The Job's `kueue.x-k8s.io/queue-name` label selects the `LocalQueue`. 2. The `LocalQueue`'s `spec.clusterQueue` selects the `ClusterQueue` that provides quota. 3. When the `Workload` is admitted, its request is deducted from that `ClusterQueue`'s quota and returned when it finishes. 4. If quota is short, the `Workload` waits and the Job stays at `job.spec.suspend: true`. What shares the quota is not Jobs or `LocalQueue`s but the admitted `Workload`s. ### Seven Optional Ones | CRD | Role | | :--- | :--- | | `Cohort` | Groups `ClusterQueue`s 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. ```yaml # 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: NoSchedule ``` ## Quota Lives Only in ClusterQueue - **`ClusterQueue`**: the actual quota pool. - **`LocalQueue`**: an entrance with no limit of its own. `LocalQueue`s that point to the same `ClusterQueue` do not split it. They compete for one pool. ```yaml 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 `ClusterQueue`s in the same `Cohort` | `LocalQueue` exists not to divide quota but to let ordinary users reach a cluster-scoped `ClusterQueue` with namespace-level permissions.