Gang Scheduling

Configure gang scheduling with JobSet using the Kubernetes WAS APIs

This example configures gang scheduling so that all 6 pods (3 replicas × 2 completions) in a JobSet must be schedulable before any of them are admitted.

Step 1: Create the Workload

The Workload references the JobSet and defines a pod group template with a gang scheduling policy:

apiVersion: scheduling.k8s.io/v1alpha2
kind: Workload
metadata:
  name: js-abc
spec:
  controllerRef:
    apiGroup: jobset.x-k8s.io
    kind: JobSet
    name: js
  podGroupTemplates:
  - name: workers
    schedulingPolicy:
      gang:
        minCount: 6

The controllerRef links the Workload to the JobSet. The podGroupTemplates entry defines a gang scheduling policy requiring a minimum of 6 pods to be schedulable.

Step 2: Create the PodGroup

The PodGroup references the pod group template defined in the Workload:

apiVersion: scheduling.k8s.io/v1alpha2
kind: PodGroup
metadata:
  name: js-abc-workers-def
  namespace: default
spec:
  podGroupTemplateRef:
    workload:
      workloadName: js-abc
      podGroupTemplateName: workers
  schedulingPolicy:
    gang:
      minCount: 6

Step 3: Create the JobSet

The JobSet pods reference the PodGroup through schedulingGroup.podGroupName:

apiVersion: jobset.x-k8s.io/v1alpha2
kind: JobSet
metadata:
  name: js
spec:
  replicatedJobs:
  - name: rj
    replicas: 3
    template:
      spec:
        completions: 2
        parallelism: 2
        backoffLimit: 0
        template:
          spec:
            terminationGracePeriodSeconds: 0
            schedulingGroup:
              podGroupName: js-abc-workers-def
            containers:
            - name: worker
              image: busybox
              command: ["/bin/sh", "-c", "sleep infinity"]
              # Pick resource requests appropriate for your cluster and workload.
              # These values are just an example.
              resources:
                requests:
                  cpu: "4"

With gang scheduling and minCount: 6, the scheduler ensures all 6 pods can be placed before scheduling any of them. If the cluster cannot accommodate all pods simultaneously, none will be scheduled — preventing partial scheduling where some pods run while others remain pending.