Updated on 2024-12-16 GMT+08:00

Configuring a Scheduling Policy of a Component Instance

Kubernetes supports node affinity and pod affinity/anti-affinity. You can configure custom rules for affinity and anti-affinity scheduling. For example, you can deploy frontend pods and backend pods together, deploy the same type of applications onto specific nodes, or deploy applications onto different nodes.

Kubernetes affinity applies to nodes and pods.

  • Node affinity: Kubernetes can schedule workloads to affinity nodes based on their labels and label values. For example, some nodes support GPU computing, and node affinity scheduling can guarantee that high-performance computing pods run on these GPU nodes.
  • Workload affinity/anti-affinity: Kubernetes offers workload affinity and anti-affinity scheduling, which allows flexible scheduling of new workloads on either related or unrelated nodes. This results in improved cluster performance and utilization. For example, frontend pods and backend pods that frequently communicate with each other can be preferentially scheduled to the same node or AZ to minimize network latency.

    Workload affinity and anti-affinity require time for computing, which significantly slows down scheduling in large-scale clusters. Do not enable workload affinity and anti-affinity in a cluster that contains hundreds of nodes.

You can Configuring an Affinity Scheduling Policy of a Node and Configuring an Affinity/Anti-affinity Scheduling Policy of a Workload for container-deployed component instances when configuring Advanced Settings.

Configuring an Affinity Scheduling Policy of a Node

  1. Choose Advanced Settings > Scheduling Policy.
  2. Select a type of the node affinity scheduling rule.

    • Mandatory: hard constraints that must be met. If multiple Mandatory rules are added, scheduling will be performed if one of the rules is met.
    • Best effort: soft constraints that are met as much as possible. If multiple Best effort rules are added, scheduling will be performed if one or none of the rules is met.

  3. Click Add.
  4. Select Node for Object Type.
  5. Add objects as required.

    • Add a policy: Click Add Policy and set the scheduling policy parameters by referring to the following table. You can customize a scheduling policy.
    • Specify a node: Click Specify Node to quickly select the node to be scheduled. You do not need to manually enter the node label and label value. The kubernetes.io/hostname label is used when you specify a node.
    • Specify an AZ: Click Specify AZ to quickly select the AZ to be scheduled. You do not need to manually enter the AZ label and label value. The failure-domain.beta.kubernetes.io/zone label is used when you specify an AZ.

    Parameter

    Description

    Weight

    This parameter is mandatory when the policy type selected in 2 is Best effort.

    During scheduling, the scheduler adds the weight to the scores of other priority functions and schedules pods to the node with the largest total score.

    The weight ranges from 1 to 100.

    Label Name

    When you click Add Policy to customize a scheduling policy, enter the node label to be matched.

    Operators

    • When you click Add Policy to customize a scheduling policy, set the following mapping relationships:
      • In: The label of the affinity object is in the label value list (values field).
      • NotIn: The label of the affinity object is not in the label value list (values field).
      • Exists: The affinity object has a specified label name.
      • DoesNotExist: The affinity object does not have a specified label name.
      • Gt: The label value of the scheduling node exceeds what is listed (character string comparison).
      • Lt: The label value of the scheduling node is under what is listed (character string comparison).
    • When configuring a Specify Node or Specify AZ scheduling policy, set the following matching relationships:
      • In: The label of the affinity object is in the label value list (values field).
      • NotIn: The label of the affinity object is not in the label value list (values field).

    Label Value

    When you click Add Policy to customize a scheduling policy, enter the label value corresponding to the label name of the node based on the selected operator.

    • If Operators is In or NotIn, enter characters for the label value. Separate multiple labels by semicolons (;). Example:
      str1;str2;str3
    • If Operators is Exists or DoesNotExist, the label value can be empty.
    • If Operators is Gt or Lt, enter an integer for the label value, for example, 5 or -5.

  6. Click OK.

Configuring an Affinity/Anti-affinity Scheduling Policy of a Workload

  1. Choose Advanced Settings > Scheduling Policy.
  2. Select a type of the workload affinity or anti-affinity scheduling rule by referring to the following table.

    Scheduling Policy

    Rule Type

    Description

    Affinity

    Mandatory

    Hard constraints that must be met.

    Filter pods that require affinity by label. If a pod that meets the filter criteria has been running on a node within the node range specified by the node label, the scheduler will forcibly schedule the created pod to this node range.

    NOTE:

    When multiple affinity policies are added, multiple labels are configured for filtering. A pod meets the filter criteria only when it has all the specified labels.

    Best effort

    Soft constraints that are met as much as possible.

    Filter pods that require affinity by label. If a pod that meets the filter criteria has been running on a node within the node range specified by the node label, the scheduler will preferentially schedule the created pod to this node range.

    NOTE:

    When multiple affinity policies are added, multiple labels are configured for filtering. A pod meets the filter criteria only when it has all the specified labels.

    Anti-affinity

    Mandatory

    Hard constraints that must be met.

    Filter one or more pods that require affinity by label. If a pod that meets the filter criteria has been running on a node within the node range specified by the node label, the scheduler will not schedule the created pod to this node range.

    NOTE:

    When multiple anti-affinity policies are added, multiple labels are configured for filtering. A pod meets the filter criteria if it has one of the specified labels.

    Best effort

    Soft constraints that are met as much as possible.

    Filter one or more pods that require affinity by label. If a pod that meets the filter criteria has been running on a node within the node range specified by the node label, the scheduler will preferentially schedule the created pod to other node range.

    NOTE:

    When multiple anti-affinity policies are added, multiple labels are configured for filtering. A pod meets the filter criteria if it has one of the specified labels.

  3. Click Add.
  4. Select Workload for Object Type.
  5. Add objects as required.

    • Click Add Policy to customize a scheduling policy. The scheduling policy is implemented based on node labels.
    • Click Specify Component, select the component to be scheduled, and click OK to quickly select the component to be scheduled. You do not need to manually enter the component label and label value.

      Parameter

      Description

      Weight

      This parameter is mandatory when the policy type selected in 2 is Best effort.

      During scheduling, the scheduler adds the weight to the scores of other priority functions and schedules pods to the node with the largest total score.

      The weight ranges from 1 to 100.

      Namespace

      Select the namespace to which the object belongs. This parameter specifies the namespace in which the scheduling policy takes effect.

      Label Name

      • When you click Add Policy to customize a scheduling policy, enter the workload label to be matched.
      • When you click Specify Component to set the scheduling policy for a specified component, you can use the default label or customize a label.

      Operators

      When you click Add Policy to customize a scheduling policy, set the matching relationship.

      • In: The label of the affinity or anti-affinity object is in the label value list (values field).
      • NotIn: The label of the affinity or anti-affinity object is not in the label value list (values field).
      • Exists: The affinity or anti-affinity object has a specified label name.
      • DoesNotExist: The affinity or anti-affinity object does not have a specified label name.

      Label Value

      Enter the label value corresponding to the workload label name based on the selected operator.

      • If Operators is In or NotIn, enter characters for the label value. Separate multiple labels by semicolons (;). Example:
        str1;str2;str3
      • If Operators is Exists or DoesNotExist, the label value can be empty.

  6. Click OK.