Controlling pod placement by using pod topology spread constraints

    By using a pod topology spread constraint, you provide fine-grained control over the distribution of pods across failure domains to help achieve high availability and more efficient resource utilization.

    OKD administrators can label nodes to provide topology information, such as regions, zones, nodes, or other user-defined domains. After these labels are set on nodes, users can then define pod topology spread constraints to control the placement of pods across these topology domains.

    You specify which pods to group together, which topology domains they are spread among, and the acceptable skew. Only pods within the same namespace are matched and grouped together when spreading due to a constraint.

    The following steps demonstrate how to configure pod topology spread constraints to distribute pods that match the specified labels based on their zone.

    Prerequisites

    • A cluster administrator has added the required labels to nodes.

    Procedure

    1. Create a spec and specify a pod topology spread constraint:

      Example pod-spec.yaml file

    The following examples demonstrate pod topology spread constraint configurations.

    This example Pod spec defines one pod topology spread constraint. It matches on pods labeled foo:bar, distributes among zones, specifies a skew of 1, and does not schedule the pod if it does not meet these requirements.

    Multiple pod topology spread constraints example

    This example spec defines two pod topology spread constraints. Both match on pods labeled foo:bar, specify a skew of 1, and do not schedule the pod if it does not meet these requirements.

    The first constraint distributes pods based on a user-defined label node, and the second constraint distributes pods based on a user-defined label rack. Both constraints must be met for the pod to be scheduled.