This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

CompositePodGroup API

Feature state: Beta since Kubernetes v1.38; disabled by default
More information about this feature

To use this feature, you (or a cluster administrator) will need to enable the CompositePodGroup feature gate for all relevant components in your cluster.

See Enable Or Disable Feature Gates for more information.

A CompositePodGroup is a runtime object that represents a non-leaf node in a multi-level workload hierarchy. While the Workload API defines static scheduling policy templates, CompositePodGroup and PodGroup objects are the runtime counterparts that carry policies and hierarchy references for a specific workload instance.

What is a CompositePodGroup?

The CompositePodGroup API resource is part of the scheduling.k8s.io/v1beta1 API group. Your cluster must have that API group enabled, as well as the CompositePodGroup feature gate, before you can use this API.

A CompositePodGroup represents a grouping of child groups (which can be CompositePodGroup or PodGroup objects). It carries scheduling policies, disruption modes, priority settings, and optional topology constraints that apply collectively across its child groups.

API structure

A CompositePodGroup consists of a spec that defines the desired scheduling behavior for its child groups, and a status subresource.

Scheduling policy

Each CompositePodGroup carries a scheduling policy (basic or gang) in spec.schedulingPolicy. When a workload controller creates a CompositePodGroup, this policy is copied from the Workload's CompositePodGroupTemplate at creation time.

For a gang policy on a CompositePodGroup, the minGroupCount field specifies the minimum number of child groups that must be schedulable simultaneously:

spec:
  schedulingPolicy:
    gang:
      minGroupCount: 2

While the policy type itself (basic or gang) cannot be changed after creation, minGroupCount is mutable to support workload scaling. Updates to minGroupCount only apply to future scheduling cycles and do not affect already-scheduled Pods.

Parent group reference

Non-root CompositePodGroup resources specify their parent group using spec.parentCompositePodGroupName. Root CompositePodGroup objects leave this field unset.

spec:
  parentCompositePodGroupName: root-group-0

Workload reference

The required spec.workloadRef field links the CompositePodGroup back to the CompositePodGroupTemplate in the Workload object it was derived from.

spec:
  workloadRef:
    workloadName: hierarchical-workload
    templateName: replica-group

Status

The scheduler updates status.conditions on each CompositePodGroup to report whether the scheduling requirements for the subtree under that CompositePodGroup have been satisfied. The primary condition is CompositePodGroupInitiallyScheduled, which is True when all required child groups have been placed and False when scheduling fails.

Note:

The CompositePodGroupInitiallyScheduled condition reflects the initial scheduling decision only. The scheduler does not update it if Pods or child groups later fail, are deleted, or are evicted.

See the CompositePodGroup conditions section for the full list of conditions and reasons.

Creating a CompositePodGroup

Workload controllers create CompositePodGroup objects automatically from Workload templates at runtime.

The following manifest creates a root CompositePodGroup with a gang scheduling policy that requires at least 2 child groups to be schedulable simultaneously:

apiVersion: scheduling.k8s.io/v1beta1
kind: CompositePodGroup
metadata:
  name: root-group-0
  namespace: default
spec:
  workloadRef:
    workloadName: hierarchical-workload
    templateName: root
  schedulingPolicy:
    gang:
      minGroupCount: 2

You can inspect CompositePodGroup resources in your cluster:

kubectl get compositepodgroups

To view details for a specific composite group:

kubectl describe compositepodgroup root-group-0

How it fits together

The relationship between controllers, Workloads, CompositePodGroups, PodGroups, and Pods follows this pattern:

  1. The workload controller creates a Workload defining a tree of CompositePodGroupTemplates and leaf PodGroupTemplates.
  2. For each runtime instance, the controller creates a root CompositePodGroup, descendant CompositePodGroup objects, and leaf PodGroup objects in a top-down manner.
  3. The controller creates Pods that reference their leaf PodGroup via spec.schedulingGroup.podGroupName.

The following example illustrates a complete manifest hierarchy for a two-level workload:

apiVersion: scheduling.k8s.io/v1beta1
kind: Workload
metadata:
  name: hierarchical-workload
  namespace: default
spec:
  compositePodGroupTemplates:
  - name: root
    schedulingPolicy:
      gang:
        minGroupCount: 2
    podGroupTemplates:
    - name: workers-a
      schedulingPolicy:
        gang:
          minCount: 4
    - name: workers-b
      schedulingPolicy:
        gang:
          minCount: 4
---
apiVersion: scheduling.k8s.io/v1beta1
kind: CompositePodGroup
metadata:
  name: root-group-0
  namespace: default
spec:
  workloadRef:
    workloadName: hierarchical-workload
    templateName: root
  schedulingPolicy:
    gang:
      minGroupCount: 2
---
apiVersion: scheduling.k8s.io/v1beta1
kind: PodGroup
metadata:
  name: workers-a-0
  namespace: default
spec:
  parentCompositePodGroupName: root-group-0
  workloadRef:
    workloadName: hierarchical-workload
    templateName: workers-a
  schedulingPolicy:
    gang:
      minCount: 4
---
apiVersion: scheduling.k8s.io/v1beta1
kind: PodGroup
metadata:
  name: workers-b-0
  namespace: default
spec:
  parentCompositePodGroupName: root-group-0
  workloadRef:
    workloadName: hierarchical-workload
    templateName: workers-b
  schedulingPolicy:
    gang:
      minCount: 4
---
apiVersion: v1
kind: Pod
metadata:
  name: worker-a-0
  namespace: default
spec:
  schedulingGroup:
    podGroupName: workers-a-0
  containers:
  - name: worker
    image: registry.k8s.io/pause:3.9

The Workload acts as a long-lived policy template, while CompositePodGroup and PodGroup resources handle per-instance runtime scheduling state.

What's next

1 - CompositePodGroup Lifecycle

Feature state: Beta since Kubernetes v1.38; disabled by default
More information about this feature

To use this feature, you (or a cluster administrator) will need to enable the CompositePodGroup feature gate for all relevant components in your cluster.

See Enable Or Disable Feature Gates for more information.

A CompositePodGroup represents a non-leaf node in a multi-level PodGroup hierarchy. Unlike PodGroup resources, CompositePodGroup resources do not directly contain Pods. Instead, they maintain a hierarchy of descendant CompositePodGroup and PodGroup objects and carry scheduling policies that apply to its children groups.

Ownership and garbage collection

A CompositePodGroup object, together with its descendant CompositePodGroup and PodGroup resources, is owned by the workload controller that created it via Kubernetes ownerReferences. When the owning workload object gets deleted, cascading garbage collection automatically deletes the associated group hierarchy.

CompositePodGroup names must be unique within a namespace and must be valid DNS subdomains.

Creation ordering

To ensure proper hierarchy resolution and scheduling, workload controllers create resources in a top-down order:

  1. Workload: Defines static templates (CompositePodGroupTemplates and PodGroupTemplates).
  2. Root CompositePodGroup: Created with spec.workloadRef pointing to the root template in the Workload.
  3. Descendant CompositePodGroups and PodGroups: Created top-down. Each child group specifies its parent by using spec.parentCompositePodGroupName and its template using spec.workloadRef.
  4. Pods: Created with spec.schedulingGroup.podGroupName pointing to their leaf PodGroup.

If a group references a parent CompositePodGroup that does not exist, or if a Pod references a PodGroup that has not yet been created, the scheduler holds off scheduling until all parent resources in the hierarchy exist.

Deletion protection

A CompositePodGroup cannot be fully deleted while any of its child groups still exist. A dedicated finalizer ensures that deletion is blocked until all groups referencing the CompositePodGroup have been deleted.

Limitations and validation rules

API validation and limits

kube-apiserver enforces the following constraints at creation or update time:

  • List item limit: Each compositePodGroupTemplates and podGroupTemplates list at any level of a Workload is capped at a maximum of 8 items.
  • Required Workload reference: Every CompositePodGroup, as well as any PodGroup that sets spec.parentCompositePodGroupName, must specify spec.workloadRef.
  • Immutable hierarchy references: spec.parentCompositePodGroupName and spec.workloadRef on groups, as well as spec.schedulingGroup on Pods, are immutable after creation.
  • Compatibility of disruption mode and scheduling policy: A CompositePodGroup, PodGroup or a group template with the basic scheduling policy cannot specify the all disruption mode.

kube-apiserver also validates priority consistency, preemption policy consistency, parent-child configuration constraints, and the maximum nesting depth of 5 levels (up to 4 levels of CompositePodGroupTemplate plus the leaf PodGroupTemplate level) on Workload templates at creation time.

Runtime hierarchy validation

Before scheduling a CompositePodGroup hierarchy, kube-scheduler validates the following rules across all runtime objects in the hierarchy:

  • Consistent scheduler name: All Pods across an entire CompositePodGroup hierarchy must use the same spec.schedulerName.
  • Consistent priority: All Pods and all groups across an entire CompositePodGroup hierarchy must specify the same value of spec.priority.
  • Parent-child configuration constraints: Child groups of a CompositePodGroup with the gang scheduling policy must have the gang scheduling policy as well. Similarly, child groups of a CompositePodGroup with the all disruption mode must have the all disruption mode as well.
  • Consistent Workload references: All groups in a group hierarchy must refer to the same Workload object in the spec.workloadRef.workloadName field.
  • Consistent preemption policy: All Pods and all groups across an entire CompositePodGroup hierarchy must specify the same spec.preemptionPolicy.
  • Maximum nesting depth: Runtime group hierarchies support a maximum depth of 5 levels (up to 4 levels of CompositePodGroup plus the leaf PodGroup level).

If kube-scheduler detects any of these runtime validation violations, it refrains from scheduling the hierarchy. It sets the CompositePodGroupInitiallyScheduled condition to False with reason CompositePodGroupError on CompositePodGroup objects and the PodGroupInitiallyScheduled condition to False with reason PodGroupError on PodGroup objects in the hierarchy.

What's next