4.17. Controlling placement of broker pods on OpenShift Container Platform nodes


You can control the placement of AMQ Broker pods on OpenShift Container Platform nodes by using node selectors, tolerations, or affinity and anti-affinity rules.

Node selectors
A node selector allows you to schedule a broker pod on a specific node.
Tolerations
A toleration enables a broker pod to be scheduled on a node if the toleration matches a taint configured for the node. Without a matching pod toleration, a taint allows a node to refuse to accept a pod.
Affinity/Anti-affinity
Node affinity rules control which nodes a pod can be scheduled on based on the node’s labels. Pod affinity and anti-affinity rules control which nodes a pod can be scheduled on based on the pods already running on that node.

4.17.1. Placing pods on specific nodes using node selectors

A node selector specifies a key-value pair that requires the broker pod to be scheduled on a node that has matching key-value pair in the node label.

The following example shows how to configure a node selector to schedule a broker pod on a specific node.

Prerequisites

Procedure

  1. Create a Custom Resource (CR) instance based on the main broker CRD.

    1. Using the OpenShift command-line interface:

      1. Log in to OpenShift as a user that has privileges to deploy CRs in the project for the broker deployment.

        oc login -u <user> -p <password> --server=<host:port>
      2. Open the sample CR file called broker_activemqartemis_cr.yaml that was included in the deploy/crs directory of the Operator installation archive that you downloaded and extracted.
    2. Using the OpenShift Container Platform web console:

      1. Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
      2. Start a new CR instance based on the main broker CRD. In the left pane, click Administration Custom Resource Definitions.
      3. Click the ActiveMQArtemis CRD.
      4. Click the Instances tab.
      5. Click Create ActiveMQArtemis.

        Within the console, a YAML editor opens, enabling you to configure a CR instance.

  2. In the deploymentPlan section of the CR, add a nodeSelector section and add the node label that you want to match to select a node for the pod. For example:

    spec:
        deploymentPlan:
          nodeSelector:
            app: broker1

    In this example, the broker pod is scheduled on a node that has a app: broker1 label.

  3. Deploy the CR instance.

    1. Using the OpenShift command-line interface:

      1. Save the CR file.
      2. Switch to the project in which you are creating the broker deployment.

        $ oc project <project_name>
      3. Create the CR instance.

        $ oc create -f <path/to/custom_resource_instance>.yaml
    2. Using the OpenShift web console:

      1. When you have finished configuring the CR, click Create.

Additional resources

For more information about node selectors in OpenShift Container Platform, see Placing pods on specific nodes using node selectors in the OpenShift Container Platform documentation.

4.17.2. Controlling pod placement using tolerations

Taints and tolerations control whether pods can or cannot be scheduled on specific nodes. A taint allows a node to refuse to schedule a pod unless the pod has a matching toleration. You can use taints to exclude pods from a node so the node is reserved for specific pods, such as broker pods, that have a matching toleration.

Having a matching toleration permits a broker pod to be scheduled on a node but does not guarantee that the pod is scheduled on that node. To guarantee that the broker pod is scheduled on the node that has a taint configured, you can configure affinity rules. For more information, see 第 4.17.3 节 “Controlling pod placement using affinity and anti-affinity rules”

The following example shows how to configure a toleration to match a taint that is configured on a node.

Prerequisites

  • You should be familiar with how to use a CR instance to create a basic broker deployment. See 第 3.4.1 节 “Deploying a basic broker instance”.
  • Apply a taint to the nodes which you want to reserve for scheduling broker pods. A taint consists of a key, value, and effect. The taint effect determines if:

    • existing pods on the node are evicted
    • existing pods are allowed to remain on the node but new pods cannot be scheduled unless they have a matching toleration
    • new pods can be scheduled on the node if necessary, but preference is to not schedule new pods on the node.

For more information about applying taints, see Controlling pod placement using node taints in the OpenShift Container Platform documentation.

Procedure

  1. Create a Custom Resource (CR) instance based on the main broker CRD.

    1. Using the OpenShift command-line interface:

      1. Log in to OpenShift as a user that has privileges to deploy CRs in the project for the broker deployment.

        oc login -u <user> -p <password> --server=<host:port>
      2. Open the sample CR file called broker_activemqartemis_cr.yaml that was included in the deploy/crs directory of the Operator installation archive that you downloaded and extracted.
    2. Using the OpenShift Container Platform web console:

      1. Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
      2. Start a new CR instance based on the main broker CRD. In the left pane, click Administration Custom Resource Definitions.
      3. Click the ActiveMQArtemis CRD.
      4. Click the Instances tab.
      5. Click Create ActiveMQArtemis.

        Within the console, a YAML editor opens, enabling you to configure a CR instance.

  2. In the deploymentPlan section of the CR, add a tolerations section. In the tolerations section, add a toleration for the node taint that you want to match. For example:

    spec:
         deploymentPlan:
            tolerations:
            - key: "app"
              value: "amq-broker"
              effect: "NoSchedule"

    In this example, the toleration matches a node taint of app=amq-broker:NoSchedule, so the pod can be scheduled on a node that has this taint configured.

注意

To ensure that the broker pods are scheduled correctly, do not specify a tolerationsSeconds attribute in the tolerations section of the CR.

  1. Deploy the CR instance.

    1. Using the OpenShift command-line interface:

      1. Save the CR file.
      2. Switch to the project in which you are creating the broker deployment.

        $ oc project <project_name>
      3. Create the CR instance.

        $ oc create -f <path/to/custom_resource_instance>.yaml
    2. Using the OpenShift web console:

      1. When you have finished configuring the CR, click Create.

Additional resources

For more information about taints and tolerations in OpenShift Container Platform, see Controlling pod placement using node taints in the OpenShift Container Platform documentation.

You can control pod placement using node affinity, pod affinity, or pod anti-affinity rules. Node affinity allows a pod to specify an affinity towards a group of target nodes. Pod affinity and anti-affinity allows you to specify rules about how pods can or cannot be scheduled relative to other pods that are already running on a node.

Node affinity allows a broker pod to specify an affinity towards a group of nodes that it can be placed on. A broker pod can be scheduled on any node that has a label with the same key-value pair as the affinity rule that you create for a pod.

The following example shows how to configure a broker to control pod placement by using node affinity rules.

Prerequisites

  • You should be familiar with how to use a CR instance to create a basic broker deployment. See 第 3.4.1 节 “Deploying a basic broker instance”.
  • Assign a common label to the nodes in your OpenShift Container Platform cluster that can schedule the broker pod, for example, zone: emea.

Procedure

  1. Create a Custom Resource (CR) instance based on the main broker CRD.

    1. Using the OpenShift command-line interface:

      1. Log in to OpenShift as a user that has privileges to deploy CRs in the project for the broker deployment.

        oc login -u <user> -p <password> --server=<host:port>
      2. Open the sample CR file called broker_activemqartemis_cr.yaml that was included in the deploy/crs directory of the Operator installation archive that you downloaded and extracted.
    2. Using the OpenShift Container Platform web console:

      1. Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
      2. Start a new CR instance based on the main broker CRD. In the left pane, click Administration Custom Resource Definitions.
      3. Click the ActiveMQArtemis CRD.
      4. Click the Instances tab.
      5. Click Create ActiveMQArtemis.

        Within the console, a YAML editor opens, enabling you to configure a CR instance.

  2. In the deploymentPlan section of the CR, add the following sections: affinity, nodeAffinity, requiredDuringSchedulingIgnoredDuringExecution, and nodeSelectorTerms. In the nodeSelectorTerms section, add the - matchExpressions parameter and specify the key-value string of a node label to match. For example:

    spec:
      deploymentPlan:
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
              - matchExpressions:
                - key: zone
                  operator: In
                  values:
                  - emea

    In this example, the affinity rule allows the pod to be scheduled on any node that has a label with a key of zone and a value of emea.

  3. Deploy the CR instance.

    1. Using the OpenShift command-line interface:

      1. Save the CR file.
      2. Switch to the project in which you are creating the broker deployment.

        $ oc project <project_name>
      3. Create the CR instance.

        $ oc create -f <path/to/custom_resource_instance>.yaml
    2. Using the OpenShift web console:

      1. When you have finished configuring the CR, click Create.

Additional resources

For more information about affinity rules in OpenShift Container Platform, see Controlling pod placement on nodes using node affinity rules in the OpenShift Container Platform documentation.

Anti-affinity rules allow you to constrain which Openshift node a broker pod can be scheduled on based on the labels of pods already running on the node.

You can use anti-affinity rules to ensure that multiple broker pods are not scheduled on the same Openshift node, which creates a single point of failure.

Prerequisites

Procedure

  1. Edit the ActiveMQArtemis CR instance for your first broker deployment.
  2. In the deploymentPlan section of the CR, add a labels section. Create an identifying label for the broker so that you can create an anti-affinity rule based on the label in your second deployment. For example:

    spec:
      ...
        deploymentPlan:
          labels:
            name: broker1
  3. Save the CR.
  4. Edit the ActiveMQArtemis CR instance for your second broker deployment.
  5. In the deploymentPlan section of the CR, add the following sections: affinity, podAntiAffinity, requiredDuringSchedulingIgnoredDuringExecution, and labelSelector. In the labelSelector section, add the matchExpressions parameter and specify the key-value string of the label to match. A pod in this deployment cannot be scheduled on a node that contains a pod with the matching label.

    spec:
      deploymentPlan:
        affinity:
          podAntiAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              - labelSelector:
                  matchExpressions:
                    - key: name
                      operator: In
                      values:
                        - broker1
                topologyKey: topology.kubernetes.io/zone

    In this example, the pod anti-affinity rule prevents a pod from being placed on the same node as a pod that has a label with a key of name and a value of broker1, which is the label assigned to the broker in your first deployment.

  6. Save the CR.

Additional resources

For more information about affinity rules in OpenShift Container Platform, see Controlling pod placement on nodes using node affinity rules in the OpenShift Container Platform documentation.

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部