Run LeaderWorkerSet
This page shows how to leverage Kueue’s scheduling and resource management capabilities when running LeaderWorkerSet.
We demonstrate how to support scheduling LeaderWorkerSets where a group of Pods constitutes a unit of admission represented by a Workload. This allows to scale-up and down LeaderWorkerSets group by group.
This integration is based on the Plain Pod Group integration.
This guide is for serving users that have a basic understanding of Kueue. For more information, see Kueue’s overview.
Before you begin
The
leaderworkerset.x-k8s.io/leaderworkersetintegration is enabled by default.For Kueue v0.15 and earlier, learn how to install Kueue with a custom manager configuration and ensure that you have the
leaderworkerset.x-k8s.io/leaderworkersetintegration enabled, for example:apiVersion: config.kueue.x-k8s.io/v1beta2 kind: Configuration integrations: frameworks: - "leaderworkerset.x-k8s.io/leaderworkerset"Pod integration requirementsSince Kueue v0.15, you don’t need to explicitly enable
"pod"integration to use the"leaderworkerset.x-k8s.io/leaderworkerset"integration.For Kueue v0.14 and earlier,
"pod"integration must be explicitly enabled.See Run Plain Pods for configuration details.
Check Administer cluster quotas for details on the initial Kueue setup.
Running a LeaderWorkerSet admitted by Kueue
When running a LeaderWorkerSet on Kueue, take into consideration the following aspects:
a. Queue selection
The target local queue should be specified in the metadata.labels section of the LeaderWorkerSet configuration.
metadata:
labels:
kueue.x-k8s.io/queue-name: user-queue
b. Configure the resource needs
The resource needs of the workload can be configured in the spec.template.spec.containers.
spec:
leaderWorkerTemplate:
leaderTemplate:
spec:
containers:
- resources:
requests:
cpu: "100m"
workerTemplate:
spec:
containers:
- resources:
requests:
cpu: "100m"
c. Scaling
You can perform scale up or scale down operations on a LeaderWorkerSet .spec.replicas.
The unit of scaling is a LWS group. By changing the number of replicas in the LWS you can create
or delete entire groups of Pods. As a result of scale up the newly created group of Pods is
suspended by a scheduling gate, until the corresponding Workload is admitted.
d. Updating the Pod templates
While Kueue manages a LeaderWorkerSet, it rejects changes to the fields of the Pod templates
that affect admission, such as the resource requests, the nodeSelector or the affinity.
Since Kueue v0.21, you can add tolerations to the Pod templates, for example to tolerate a new node taint.
Existing tolerations cannot be removed or changed, because the new Pods could then fail to run
on the nodes that Kueue already assigned to the LeaderWorkerSet.
Kueue copies the new tolerations to the Workloads of the LeaderWorkerSet:
- A pending Workload can be admitted to the nodes whose taints they tolerate.
- An admitted Workload keeps its admission, and Topology Aware Scheduling checks node taints against the new tolerations, so the restarted Pods can keep running on the assigned nodes.
Kueue copies the new tolerations to the Workloads of all groups right away, while LeaderWorkerSet updates their Pods gradually. Until this rolling update completes:
- Do not add the taints that the new tolerations match.
- Do not raise
rolloutStrategy.rollingUpdateConfiguration.partition. LeaderWorkerSet would keep the groups below the partition, and the groups that a scale-up creates there, on the Pods without the new tolerations.
Kueue rejects adding tolerations while the partition is greater than 0, because LeaderWorkerSet does not update the groups below the partition.
In MultiKueue, Kueue also copies the new tolerations to the Workloads and the LeaderWorkerSet
on the worker cluster. Together with the tolerations, Kueue copies the
rolloutStrategy.rollingUpdateConfiguration.partition, so that the worker cluster updates all groups too.
To turn this off, disable the AllowAddingPodTemplateTolerations
feature gate.
Since Kueue v0.21, you can add, remove or change the containers and the initContainers of the
Pod templates, including sidecar containers, when the effective resource requests of the Pods stay
the same and no host port is added. Kueue does not change the Workloads.
For example, you can change the image or the arguments, move requests between containers, or add
a container whose requests fit within the current effective requests of the Pods.
Kueue computes the effective requests as for the quota of the Workloads: limits are used as missing
requests, then the defaults of the LimitRanges in the namespace fill in the requests that are still
missing. So adding a container without requests is rejected when a LimitRange sets default requests
or limits. Requests of zero use no quota, so Kueue ignores them.
Kueue rejects adding a hostPort, because the new Pods could then fail to fit on the nodes that
Kueue already assigned. You can remove a host port or change the other fields of the ports.
With hostNetwork: true, Kubernetes uses the containerPort as the host port when hostPort is
not set, so Kueue treats a new or changed containerPort as an added host port.
Kueue checks the effective requests against the LimitRanges at the time of the change. If you add a container without requests, and a LimitRange later sets default requests in the namespace, the new Pods request more than their Workload reserves, and Kueue keeps them gated.
In MultiKueue, when the MultiKueueRemoteSpecSync feature gate is enabled, which is the default,
Kueue also copies the containers, the init containers and the
rolloutStrategy.rollingUpdateConfiguration.partition to the LeaderWorkerSet on the worker cluster,
so that the worker cluster updates the same groups.
Earlier versions of Kueue did not copy the containers. When you upgrade the manager cluster, Kueue
copies the containers that you changed before the upgrade, for example the image, and the worker
cluster starts a rolling update of these LeaderWorkerSets.
If the worker cluster rejects the change, for example because it runs an earlier version of Kueue
or its LimitRanges set higher defaults, kueue-controller-manager logs the error, and the worker
cluster keeps the previous containers.
To turn this off, disable the AllowMutatingContainersWhenEffectiveRequestsDontChange
feature gate.
e. Group identity
Kueue supports only the default spec.groupIdentity: Ordinal. With
spec.groupIdentity: Hash, the leader Pods are managed by a Deployment and run
without admission, while the worker Pods stay gated.
Kueue rejects spec.groupIdentity: Hash when you create a LeaderWorkerSet that
Kueue manages, or when an update brings a LeaderWorkerSet under Kueue management,
for example by adding the kueue.x-k8s.io/queue-name label. In a namespace with
a default LocalQueue,
this includes a LeaderWorkerSet created without the kueue.x-k8s.io/queue-name
label, because Kueue sets the label to default on create.
A LeaderWorkerSet with spec.groupIdentity: Hash that Kueue already manages is
not rejected on update and keeps running this way. This includes one created
before Kueue added this validation, and one that Kueue started to manage without
an update, for example when its namespace started to match
managedJobsNamespaceSelector with
manageJobsWithoutQueueName
enabled. Kueue still creates its Workloads by group
ordinal, so they can be admitted and reserve quota that no Pod uses. Kueue
returns a warning when you update such a LeaderWorkerSet, for example with
kubectl apply. spec.groupIdentity is immutable, so delete the
LeaderWorkerSet and create it again with spec.groupIdentity: Ordinal.
To turn off the rejection and the warning, disable the LeaderWorkerSetRejectGroupIdentityHash
feature gate.
Kueue then accepts a LeaderWorkerSet with spec.groupIdentity: Hash, and its leader Pods
run without admission.
Example
Here is a sample LeaderWorkerSet:
apiVersion: leaderworkerset.x-k8s.io/v1
kind: LeaderWorkerSet
metadata:
name: nginx-leaderworkerset
labels:
app: nginx
kueue.x-k8s.io/queue-name: user-queue
spec:
replicas: 2
leaderWorkerTemplate:
leaderTemplate:
spec:
containers:
- name: nginx-leader
image: registry.k8s.io/nginx-slim:0.27
resources:
requests:
cpu: "100m"
ports:
- containerPort: 80
size: 3
workerTemplate:
spec:
containers:
- name: nginx-worker
image: registry.k8s.io/nginx-slim:0.27
resources:
requests:
cpu: "200m"
ports:
- containerPort: 80You can create the LeaderWorkerSet using the following command:
kubectl create -f sample-leaderworkerset.yaml
Configure Topology Aware Scheduling
For performance-sensitive workloads like large-scale inference or distributed training, you may require the Leader and Worker pods to be co-located within a specific network topology domain (e.g., a rack or a data center block) to minimize latency.
Kueue supports Topology Aware Scheduling (TAS) for LeaderWorkerSet by reading annotations from the Pod templates. To enable this:
- Configure the cluster for Topology Aware Scheduling.
- Add the
kueue.x-k8s.io/podset-required-topologyannotation to both theleaderTemplateand theworkerTemplate. - Add the
kueue.x-k8s.io/podset-group-nameannotation to both theleaderTemplateand theworkerTemplatewith the same value. This ensures that the Leader and Workers are scheduled in the same topology domain.
Example: Rack-Level Co-location
The following example uses the podset-group-name annotation to ensure that the Leader and all Workers are scheduled within the same rack (represented by the cloud.provider.com/topology-rack label).
apiVersion: leaderworkerset.x-k8s.io/v1
kind: LeaderWorkerSet
metadata:
name: nginx-leaderworkerset
labels:
app: nginx
kueue.x-k8s.io/queue-name: tas-user-queue
spec:
replicas: 2
leaderWorkerTemplate:
leaderTemplate:
metadata:
annotations:
# Require leader to be in the topology domain
kueue.x-k8s.io/podset-required-topology: "cloud.provider.com/topology-rack"
# Identify the group to ensure co-location with workers
kueue.x-k8s.io/podset-group-name: "lws-group"
spec:
containers:
- name: nginx-leader
image: registry.k8s.io/nginx-slim:0.27
resources:
requests:
cpu: "100m"
ports:
- containerPort: 80
size: 3
workerTemplate:
metadata:
annotations:
# Require workers to be in the same topology domain
kueue.x-k8s.io/podset-required-topology: "cloud.provider.com/topology-rack"
# Identify the group to ensure co-location with leader
kueue.x-k8s.io/podset-group-name: "lws-group"
spec:
containers:
- name: nginx-worker
image: registry.k8s.io/nginx-slim:0.27
resources:
requests:
cpu: "200m"
ports:
- containerPort: 80When replicas is greater than 1 (as in the example above where replicas: 2), the topology constraints apply to each replica individually. This means that for each replica, the Leader and its Workers will be co-located in the same topology domain (e.g., rack), but different replicas may be assigned to different topology domains.
Multikueue
Check MultiKueue for details on running LeaderWorkerSets in MultiKueue environment.
Troubleshooting
For general troubleshooting guidance, see the Kueue troubleshooting guide.
Long LeaderWorkerSet names
By default, Kueue stores the pod-group identifier in the
kueue.x-k8s.io/pod-group-name label, which inherits Kubernetes'
63-character label value limit. Because Kueue derives this value by appending
a group suffix to the LeaderWorkerSet name, the effective LWS name limit is
39 characters.
Enable the alpha
WorkloadIdentifierAnnotations
feature gate to store the identifier in an annotation instead, removing
Kueue’s label-length constraint. With the feature gate enabled, the effective
limit shifts to the upstream LWS constraint of 51 characters
(see Unable to Create LWS Object with a Name Exceeding 51 Characters in the LWS troubleshooting guide).
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.