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.
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
- 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”.
- Add a label to the OpenShift Container Platform node on which you want to schedule the broker pod. For more information about adding node labels, see Using node selectors to control pod placement in the OpenShift Container Platform documentation.
Procedure
Create a Custom Resource (CR) instance based on the main broker CRD.
Using the OpenShift command-line interface:
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>-
Open the sample CR file called
broker_activemqartemis_cr.yamlthat was included in thedeploy/crsdirectory of the Operator installation archive that you downloaded and extracted.
Using the OpenShift Container Platform web console:
- Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
-
Start a new CR instance based on the main broker CRD. In the left pane, click
. - Click the ActiveMQArtemis CRD.
- Click the Instances tab.
Click Create ActiveMQArtemis.
Within the console, a YAML editor opens, enabling you to configure a CR instance.
In the
deploymentPlansection of the CR, add anodeSelectorsection and add the node label that you want to match to select a node for the pod. For example:spec: deploymentPlan: nodeSelector: app: broker1In this example, the broker pod is scheduled on a node that has a
app: broker1label.Deploy the CR instance.
Using the OpenShift command-line interface:
- Save the CR file.
Switch to the project in which you are creating the broker deployment.
$ oc project <project_name>Create the CR instance.
$ oc create -f <path/to/custom_resource_instance>.yaml
Using the OpenShift web console:
- 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
Create a Custom Resource (CR) instance based on the main broker CRD.
Using the OpenShift command-line interface:
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>-
Open the sample CR file called
broker_activemqartemis_cr.yamlthat was included in thedeploy/crsdirectory of the Operator installation archive that you downloaded and extracted.
Using the OpenShift Container Platform web console:
- Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
-
Start a new CR instance based on the main broker CRD. In the left pane, click
. - Click the ActiveMQArtemis CRD.
- Click the Instances tab.
Click Create ActiveMQArtemis.
Within the console, a YAML editor opens, enabling you to configure a CR instance.
In the
deploymentPlansection of the CR, add atolerationssection. In thetolerationssection, 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.
Deploy the CR instance.
Using the OpenShift command-line interface:
- Save the CR file.
Switch to the project in which you are creating the broker deployment.
$ oc project <project_name>Create the CR instance.
$ oc create -f <path/to/custom_resource_instance>.yaml
Using the OpenShift web console:
- 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
Create a Custom Resource (CR) instance based on the main broker CRD.
Using the OpenShift command-line interface:
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>-
Open the sample CR file called
broker_activemqartemis_cr.yamlthat was included in thedeploy/crsdirectory of the Operator installation archive that you downloaded and extracted.
Using the OpenShift Container Platform web console:
- Log in to the console as a user that has privileges to deploy CRs in the project for the broker deployment.
-
Start a new CR instance based on the main broker CRD. In the left pane, click
. - Click the ActiveMQArtemis CRD.
- Click the Instances tab.
Click Create ActiveMQArtemis.
Within the console, a YAML editor opens, enabling you to configure a CR instance.
In the
deploymentPlansection of the CR, add the following sections:affinity,nodeAffinity,requiredDuringSchedulingIgnoredDuringExecution, andnodeSelectorTerms. In thenodeSelectorTermssection, add the- matchExpressionsparameter 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: - emeaIn this example, the affinity rule allows the pod to be scheduled on any node that has a label with a key of
zoneand a value ofemea.Deploy the CR instance.
Using the OpenShift command-line interface:
- Save the CR file.
Switch to the project in which you are creating the broker deployment.
$ oc project <project_name>Create the CR instance.
$ oc create -f <path/to/custom_resource_instance>.yaml
Using the OpenShift web console:
- 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
- You created two separate broker deployments. See 第 3.4.1 节 “Deploying a basic broker instance”.
Procedure
-
Edit the
ActiveMQArtemisCR instance for your first broker deployment. In the
deploymentPlansection of the CR, add alabelssection. 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- Save the CR.
-
Edit the
ActiveMQArtemisCR instance for your second broker deployment. In the
deploymentPlansection of the CR, add the following sections:affinity,podAntiAffinity,requiredDuringSchedulingIgnoredDuringExecution, andlabelSelector. In thelabelSelectorsection, add thematchExpressionsparameter 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/zoneIn 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
nameand a value ofbroker1, which is the label assigned to the broker in your first deployment.- 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.