此内容没有您所选择的语言版本。
Chapter 2. Deploying AMQ Broker on OpenShift Container Platform using an Operator
2.1. Overview of the AMQ Broker Operator
Kubernetes - and, by extension, OpenShift Container Platform - includes features such as secret handling, load balancing, service discovery, and autoscaling that enable you to build complex distributed systems. Operators are programs that enable you to package, deploy, and manage Kubernetes applications. Often, Operators automate common or complex tasks.
Commonly, Operators are intended to provide:
- Consistent, repeatable installations
- Health checks of system components
- Over-the-air (OTA) updates
- Managed upgrades
Operators use Kubernetes extension mechanisms called Custom Resource Definitions and corresponding Custom Resources to ensure that your custom objects look and act just like native, built-in Kubernetes objects. Custom Resource Definitions and Custom Resources are how you specify the configuration of the OpenShift objects that you plan to deploy.
Previously, you could use only application templates to deploy AMQ Broker on OpenShift Container Platform. While templates are effective for creating an initial deployment, they do not provide a mechanism for updating the deployment. Operators enable you to make changes while your broker instances are running, because they are always listening for changes to your Custom Resources, where you specify your configuration. When you make changes to a Custom Resource, the Operator reconciles the changes with the existing broker installation in your project, and makes it reflect the changes you have made.
2.2. Overview of Custom Resource Definitions
In general, a Custom Resource Definition (CRD) is a schema of configuration items that you can modify for a custom OpenShift object deployed with an Operator. An accompanying Custom Resource (CR) file enables you to specify values for configuration items in the CRD. If you are an Operator developer, what you expose through a CRD essentially becomes the API for how a deployed object is configured and used. You can directly access the CRD through regular HTTP curl
commands, because the CRD gets exposed automatically through Kubernetes. The Operator also interacts with Kubernetes via the kubectl
command using HTTP requests.
The main broker CRD is the broker_v2alpha1_activemqartemis
file in the deploy/crds
directory of the archive that you download and extract when installing the Operator. This CRD enables you to configure a broker deployment in a given OpenShift project. The other CRDs in the deploy/crds
directory are for configuring addresses and for the Operator to use when instantiating a scaledown controller .
When deployed, each CRD is a separate controller, running independently within the Operator.
For a complete configuration reference for each CRD see:
2.2.1. Sample broker Custom Resources
The AMQ Broker Operator archive that you download and extract during installation includes sample CR files in the deploy/crs
directory. These sample CR files enable you to:
- Deploy a minimal broker without SSL or clustering.
- Define addresses.
The broker Operator archive that you download and extract also includes CRs for example deployments in the deploy/examples
directory, as listed below.
basic-deployment.yaml
- Basic broker deployment.
persistence-deployment.yaml
- Broker deployment with persistent storage.
cluster-deployment.yaml
- Deployment of clustered brokers.
persistence-cluster-deployment.yaml
- Deployment of clustered brokers with persistent storage.
ssl-deployment.yaml
- Broker deployment with SSL security.
ssl-persistence-deployment.yaml
- Broker deployment with SSL security and persistent storage.
address-queue-create.yaml
- Address and queue creation.
aio-journal.yaml
- Use of asynchronous I/O (AIO) with the broker journal.
The procedures in the following sections show you how to use an Operator, CRD, and some CRs to create some container-based broker deployments on OpenShift Container Platform. When you have successfully completed the procedures, you will have the Operator running in an individual Pod. Each broker instance that you create will run in a separate StatefulSet containing a Pod in the project. You will use a dedicated CR to define addresses in your broker deployments.
You cannot create more than one broker deployment in a given OpenShift project by deploying multiple broker CR instances. However, when you have created a broker deployment in a project, you can deploy multiple CR instances for addresses.
2.3. Installing the AMQ Broker Operator
The procedures in this section show you how to install and deploy the AMQ Broker Operator on OpenShift Container Platform. In subsequent procedures, you use this Operator to deploy some broker instances.
Deploying the Custom Resource Definitions (CRDs) that accompany the AMQ Broker Operator requires administrator privileges for your OpenShift cluster. When the Operator is deployed, a regular user can deploy broker instances via the provided Custom Resources (CRs).
2.3.1. Getting the Operator code
This procedure shows you how to access and prepare the code you need to install the AMQ Broker Operator.
Procedure
- In your web browser, navigate to the AMQ Broker 7.5.0 Software Downloads page.
Click Download next to the Operator archive file that you want to install. Choose an archive file based on the information in the following table.
Platform Download title Compressed archive file name OpenShift Container Platform
AMQ Broker 7.5 Operator Installation Files
amq-broker-operator-7.5.0-ocp-install-examples.zip
OpenShift Container Platform on IBM Z
AMQ Broker 7.5 Operator Installation Files for IBM zSeries
amq-broker-operator-7.5.0-Z-ocp-install-examples.zip
When the download is complete, move the archive to your chosen installation directory.
This example moves the OpenShift Container Platform Operator archive to a directory called
~/broker/operator
.mkdir ~/broker/operator mv amq-broker-operator-7.5.0-ocp-install-examples.zip ~/broker/operator
In your chosen installation directory, extract the contents of the archive. For example:
cd ~/broker/operator unzip amq-broker-operator-7.5.0-ocp-install-examples.zip
Log in to OpenShift Container Platform as a cluster administrator.
$ oc login -u system:admin
Create or log in to the project in which you want to install the Operator.
$ oc new-project <project_name>
or
$ oc project <project_name>
Specify a service account to use with the Operator.
-
In the
deploy
directory of the Operator archive that you extracted, open theservice_account.yaml
file. -
Set the
kind
element toServiceAccount
. -
In the
metadata
section, assign a name to the service account. The default name isamq-broker-operator
.
-
In the
Specify a role name for the Operator.
-
Open the
role.yaml
file. This file specifies the resources that the Operator can use and modify. -
Set the
kind
element toRole
. -
In the
metadata
section, assign a name to the role. The default name isamq-broker-operator
.
-
Open the
Specify a role binding for the Operator. The role binding binds the previously-created service account to the Operator role, based on the names you specified.
Open the
role_binding.yaml
file. Add lines that look like the following:metadata: name: amq-broker-operator subjects: kind: ServiceAccount name: amq-broker-operator roleRef: kind: Role name: amq-broker-operator
2.3.2. Deploying the Operator
The procedure in this section shows you how to deploy the AMQ Broker Operator in your OpenShift project.
Prerequisites
- Starting in AMQ Broker 7.3, you use a new version of the Red Hat Container Registry to access container images. This new version of the registry requires you to become an authenticated user before you can access images. Before you can follow the procedure in this section, you must first complete the steps described in Red Hat Container Registry Authentication.
If you intend to deploy brokers with persistent storage and do not have container-native storage in your OpenShift cluster, you need to manually provision persistent volumes and ensure that they are available to be claimed by the Operator. For example, if you want to create a cluster of two brokers with persistent storage (that is, by setting
persistenceEnabled=true
in your Custom Resource), you need to have two persistent volumes available. By default, each broker instance requires storage of 2 GiB.If you specify
persistenceEnabled=false
in your Custom Resource, the deployed brokers uses ephemeral storage. Ephemeral storage means that that every time you restart the broker Pods, any existing data is lost.For more information about provisioning persistent storage in OpenShift Container Platform, see Understanding persistent storage in the OpenShift Container Platform documentation.
Procedure
In the OpenShift Container Platform web console, open the project you created, or the existing project in which you want your broker deployment.
If you created a new project, it is currently empty. You see that there are no deployments, StatefulSets, Pods, Services, or Routes.
Prepare the project to receive the operator.
Create the service account.
$ oc create -f deploy/service_account.yaml
Create the role.
$ oc create -f deploy/role.yaml
Create the role binding.
$ oc create -f deploy/role_binding.yaml
Deploy the broker CRD to the OpenShift cluster.
$ oc create -f deploy/crds/broker_v2alpha1_activemqartemis_crd.yaml
NoteYou must install the CRDs before deploying and starting the Operator. If not, the Operator logs will show messages instructing you to do so.
Deploy the addressing CRD.
$ oc create -f deploy/crds/broker_v2alpha1_activemqartemisaddress_crd.yaml
Deploy the scaledown CRD.
$ oc create -f deploy/crds/broker_v2alpha1_activemqartemisscaledown_crd.yaml
Link the pull secret associated with the account used for authentication in the Red Hat Container Registry with the
default
,deployer
, andbuilder
service accounts for your OpenShift project.$ oc secrets link --for=pull default <secret-name> $ oc secrets link --for=pull deployer <secret-name> $ oc secrets link --for=pull builder <secret-name>
NoteIn OpenShift Container Platform 4.1, you can also use the web console to associate a pull secret with a project in which you want to deploy container images such as the AMQ Broker Operator. To do this, click
. Specify the pull secret associated with the account that you use for authentication in the Red Hat Container Registry. In the
deploy
directory of the Operator archive that you downloaded and extracted, open theoperator.yaml
file. Updatespec.containers.image
with the full path to the latest Operator image for AMQ Broker 7.5 in the Red Hat Container Registry.Specify the Operator image name for your platform, based on the information in the following table.
Platform Repository name Latest version tag OpenShift Container Platform
amq7/amq-broker-rhel7-operator
0.9
OpenShift Container Platform on IBM Z
amq7/amq-broker-rhel8-operator
0.10
For example, to deploy the Operator for OpenShift Container Platform, specify the latest version tag for the Operator container image in the
amq7/amq-broker-rhel7-operator
repository, as shown below.spec: template: spec: containers: image: registry.redhat.io/amq7/amq-broker-rhel7-operator:0.9
Deploy the Operator.
$ oc create -f deploy/operator.yaml
In your OpenShift project, the
amq-broker-operator
image that you deployed starts in a new Pod.The information on the Events tab of the new Pod confirms that OpenShift has deployed the Operator image you specified, assigned a new container to a node in your OpenShift cluster, and started the new container.
In addition, if you click the Logs tab within the Pod, the output includes line like the following:
... {"level":"info","ts":1553619035.8302743,"logger":"kubebuilder.controller","msg":"Starting Controller","controller":"activemqartemisaddress-controller"} {"level":"info","ts":1553619035.830541,"logger":"kubebuilder.controller","msg":"Starting Controller","controller":"activemqartemis-controller"} {"level":"info","ts":1553619035.9306898,"logger":"kubebuilder.controller","msg":"Starting workers","controller":"activemqartemisaddress-controller","worker count":1} {"level":"info","ts":1553619035.9311671,"logger":"kubebuilder.controller","msg":"Starting workers","controller":"activemqartemis-controller","worker count":1}
The preceding output confirms that the newly-deployed Operator is communicating with Kubernetes, that the controllers for the broker and addressing are running, and that these controllers have started some workers.
2.4. Deploying a basic broker
The following procedures show you how to deploy a basic broker instance in your OpenShift project when you have installed the AMQ Broker Operator.
You cannot create more than one broker deployment in a given OpenShift project by deploying multiple broker CR instances. However, when you have created a broker deployment in a project, you can deploy multiple CR instances for addresses.
Prerequisites
- Starting in AMQ Broker 7.3, you use a new version of the Red Hat Container Registry to access container images. This new version of the registry requires you to become an authenticated user before you can access images. Before you can follow the procedure in this section, you must first complete the steps described in Red Hat Container Registry Authentication.
- The Broker Operator is already installed. See Installing the Broker Operator.
Procedure
When you have successfully installed the Operator, the Operator is running and listening for changes related to your Custom Resources (CRs). This example procedure shows you how to use a CR to deploy a basic broker in your project.
In the
deploy/crs
directory of the Operator archive that you downloaded and extracted, open thebroker_v2alpha1_activemqartemis_cr.yaml
file. This file is an instance of a basic broker Custom Resource.For the broker Operator for OpenShift Container Platform, the default contents of the file look as follows:
apiVersion: broker.amq.io/v2alpha1 kind: ActiveMQArtemis metadata: name: ex-aao application: ex-aao-app namespace: aao-demo-0 labels: ActiveMQArtemis: ex-aao application: ex-aao-app ... spec: deploymentPlan: size: 2 image: registry.redhat.io/amq7/amq-broker:7.5
size
-
Specifies the number of brokers to deploy. For a clustered deployment, this value is
2
or greater. However, for a basic broker instance, change the value to1
. image
Specifies the container image to use to launch the broker. Default values for the
image
attribute are shown in the following table.Platform Image OpenShift Container Platform
registry.redhat.io/amq7/amq-broker:7.5
OpenShift Container Platform on IBM Z
registry.redhat.io/amq7/amq-broker-openj9-11-rhel8:7.5
Deploy a basic broker, based on the
broker_v2alpha1_activemqartemis
CR.$ oc create -f deploy/crs/broker_v2alpha1_activemqartemis_cr.yaml
In the OpenShift Container Platform web console, click
(OpenShift Container Platform 4.1) or (OpenShift Container Platform 3.11). You see a new Stateful Set called ex-aao-ss
.Expand the ex-aao-ss Stateful Set section. You see that there is one Pod, corresponding to the single broker that you defined in the Custom Resource.
On the Events tab of the running Pod, you see that the broker has started.
To delete a broker deployment, delete the Custom Resource instance that you created for the deployment. It is not sufficient to delete only the Stateful Set.
Additional resources
- To learn how to connect a running broker to the AMQ Broker management console, see Connecting a broker to the AMQ Broker management console.
2.5. Applying Custom Resource changes to running broker deployments
The following are some things to note about applying Custom Resource (CR) changes to running broker deployments:
-
You cannot dynamically update the
persistenceEnabled
attribute in your CR. To change this attribute, scale your cluster down to zero brokers. Delete the existing CR. Then, recreate and redeploy the CR with your changes, also specifying a deployment size. -
If the
image
attribute in your CR uses a floating tag such as7.5
, then your deployment automatically pulls new image versions as they become available in the Red Hat Container Registry, provided that theimagePullPolicy
attribute in your deployment configuration or Stateful Set is set toAlways
. For example, if your deployment currently uses a broker image version,7.5-2
, and a newer broker image version,7.5-3
, becomes available, then your deployment automatically pulls and uses the new image version. To use the new image, each broker in the deployment scales down and then back up. If you have multiple brokers in your deployment, each broker scales down and back up, in sequence. -
The value of the
deploymentPlan.size
attribute in your CR overrides any change you make to size of your broker deployment via theoc scale
command. For example, suppose you useoc scale
to change the size of a deployment from three brokers to two, but the value ofdeploymentPlan.size
in your CR is still3
. In this case, OpenShift initially scales the deployment down to two brokers. However, when the scaledown operation is complete, the Operator restores the deployment to three brokers, as specified in the CR. - During an active scaling event, any further changes that you apply are queued by the Operator and executed only when scaling is complete. For example, suppose you scale the size of your deployment down from four brokers to one. Then, while scaledown is taking place, you also change the values of the broker administrator user name and password. In this case, the Operator queues the user name and password changes until the deployment is running with one active broker.
-
All Custom Resource changes – apart from changing the size of your deployment, or changing the value of the
expose
attribute for acceptors, connectors, or the console – cause existing brokers to scale down and then back up. If you have multiple brokers in your deployment, only one broker scales down at a time.
2.6. Configuring Operator-based broker deployments for client connections
2.6.1. Configuring brokers to accept client connections
2.6.1.1. Configuring acceptors
To enable client connections to a broker in your OpenShift deployment, you define acceptors on the broker Pod. Acceptors define how the broker accepts connections.
You define acceptors in the Custom Resource (CR) used for your broker deployment. A single acceptor can accept multiple client connections, up to a maximum limit specified by the connectionsAllowed
parameter of your acceptor configuration . You can define acceptors for both internal clients (that is, client applications in the same OpenShift cluster as the broker) and external clients (applications outside OpenShift). For each acceptor that you define, a dedicated Service and Route is created in the broker Pod.
When you create an acceptor, you specify information such as the messaging protocols to enable on the acceptor, and the port on the broker Pod to be exposed to use these protocols.
If you do not define any acceptors in your CR, then your broker Pods use a minimum configuration of a single acceptor, created by default, on port 61616. This default acceptor has only the Core protocol specified. The reason that all broker use this minimum acceptor configuration is that clustering requires the configuration, and clustering is enabled by default.
In addition, port 8161 is automatically exposed on the broker Pod for use by the AMQ Broker management console. Within the OpenShift network, this console port can be accessed via the headless service that runs in your broker deployment.
You can also specify whether to enable SSL on the acceptor, using the sslEnabled
parameter. If the acceptor uses SSL, you can specify information such as:
- The secret name used to store SSL credentials (required).
- The cipher suites and and protocols to use for SSL communication.
- Whether the acceptor uses two-way SSL, that is, mutual authentication between the broker and the client.
If the acceptor that you define uses SSL, then the SSL credentials used by the acceptor must be stored in a secret. You must create your own secret and specify this secret name in the sslSecret
parameter of your acceptor configuration. If you do not specify a custom secret name in the sslSecret
parameter, the acceptor assumes a default secret name. The default secret name uses the format <Custom Resource name>-<acceptor-name>-secret
. For example, ex-aao-amqp-secret
. The SSL credentials required in the secret are broker.ks
, which must be a base64-encoded keystore, client.ts
, which must be a base64-encoded truststore, and keyStorePassword
and trustStorePassword
, which are passwords specified in raw text. This requirement is the same for any connectors that you configure. For information about generating credentials for SSL connections, see Generating credentials for SSL connections.
To connect to the broker from outside OpenShift via a NodePort, use a URI formatted like protocol://any.ocp.node.ip:ProtocolPortNumber
. If you have configured a Route, you need to specify the Route name. The Route name must resolve to the node that’s hosting the OpenShift router. The OpenShift router uses the specified hostname to determine where to send the traffic inside the OpenShift internal network.
To configure acceptors, your Operator-based broker deployment must specify a broker container image for AMQ Broker 7.5 or later. For an example of specifying a broker container image in your deployment, see Deploying a basic broker.
The preceding information applies only to broker deployments based on the AMQ Broker Operator. If you have used application templates to create your broker deployment instead, you cannot create individual acceptors to directly connect external clients to the protocol-specific ports that OpenShift exposes on the broker Pod. For more information, see Connecting external clients to templates-based broker deployments.
Additional resources
- For a complete configuration reference for the main broker Custom Resource Definition (CRD), including configuration of acceptors, see Custom Resource Definition configuration reference.
- For information about generating credentials for SSL connections, see Generating credentials for SSL connections.
2.6.1.2. Generating credentials for SSL connections
For SSL connections, AMQ Broker requires a broker keystore, a client keystore, and a client truststore that includes the broker keystore. This procedure shows you how to generate the credentials. The procedure uses Java Keytool, a package included with the Java Development Kit.
Procedure
Generate a self-signed certificate for the broker keystore.
$ keytool -genkey -alias broker -keyalg RSA -keystore broker.ks
Export the certificate, so that it can be shared with clients.
$ keytool -export -alias broker -keystore broker.ks -file broker_cert
Generate a self-signed certificate for the client keystore.
$ keytool -genkey -alias client -keyalg RSA -keystore client.ks
Create a client truststore that imports the broker certificate.
$ keytool -import -alias broker -keystore client.ts -file broker_cert
Use the broker keystore file to create a secret to store the SSL credentials, as shown in the example below.
$ oc secrets new ex-aao-amqp-secret broker.ks client.ts
Add the secret to the service account that you created when installing the Operator, as shown in the example below.
$ oc secrets add sa/amq-broker-operator secret/ex-aao-amqp-secret
2.6.1.3. Networking services in your broker deployments
On the Networking pane of the OpenShift Container Platform web console for your broker deployment, there are two running services; a headless service and a ping service. The default name of the headless service uses the format <Custom Resource name>-hdls-svc
, for example, ex-aao-hdls-svc
. The default name of the ping service uses a format of <Custom Resource name>-ping-svc
, for example, ex-aao-ping-svc
.
The headless service provides access to ports 8161 and 61616 on each broker Pod. Port 8161 is used by the broker management console, and port 61616 is used for broker clustering.
The ping service is a service used by the brokers for discovery, and enables brokers to form a cluster within the OpenShift environment. Internally, this service exposes the 8888 port.
2.6.2. Connecting a broker to the AMQ Broker management console
The broker hosts its own management console at port 8161. Each broker Pod in your deployment has a Service and Route that provide access to the console.
The following procedure shows how to connect to the AMQ Broker management console for a running broker instance.
Prerequisites
- You have deployed a basic broker using the AMQ Broker Operator. For more information, see Deploying a basic broker.
2.6.2.1. Accessing the broker management console
Each broker Pod in your deployment has a service that provides access to the console. The default name of this service uses the format <Custom Resource name>-wconsj-<broker Pod ordinal>-svc
. For example, for broker Pod 0
of your deployment, the service name is ex-aao-wconsj-0-svc
. Each Service has a corresponding Route that uses the format `<Custom Resource name>-wconsj-<broker Pod ordinal>-svc-rte
. For example, ex-aao-wconsj-0-svc-rte
.
This procedure shows you how to access the AMQ Broker management console for a running broker instance.
Procedure
In the OpenShift Container Platform web console, click
(OpenShift Container Platform 4.1) or (OpenShift Container Platform 3.11). On the Routes pane, you see a Route corresponding to the
wconsj
Service.- Under Hostname, note the complete URL. You need to specify this URL to access the console.
In a web browser, enter the host name URL.
-
If your console configuration does not use SSL, specify
http
in the URL. In this case, DNS resolution of the host name directs traffic to port 80 of the OpenShift router. -
If your console configuration uses SSL, specify
https
in the URL. In this case, your browser defaults to port 443 of the OpenShift router. This enables a successful connection to the console if the OpenShift router also uses port 443 for SSL traffic, which the router does by default.
-
If your console configuration does not use SSL, specify
-
To log in to the management console, enter the user name and password specified in the
adminUser
andadminPassword
parameters of your broker deployment Custom Resource. If there are no values specified foradminUser
andadminPassword
, follow the instructions in Accessing management console login credentials to retrieve the credentials required to log in to the console.
2.6.2.2. Accessing management console login credentials
If you did not specify a value for adminUser
and adminPassword
in your broker Custom Resource (CR), the Operator automatically generates the broker user name and password (required to log in to the AMQ Broker management console) and stores these credentials in a secret. The default secret name has a format of <Custom Resource name>-credentials-secret
, for example, ex-aao-credentials-secret
.
This procedure shows you how to access the login credentials required to log in to the management console.
Procedure
See the complete list of secrets in your OpenShift project.
-
From the OpenShift Container Platform web console, click
(OpenShift Container Platform 4.1) or (OpenShift Container Platform 3.11). From the command line:
$ oc get secrets
-
From the OpenShift Container Platform web console, click
Open the appropriate secret to reveal the console login credentials.
-
From the OpenShift Container Platform web console, click the secret that includes your broker Custom Resource instance in its name. To see the encrypted user name and password values, click the YAML tab (OpenShift Container Platform 4.1) or
(OpenShift Container Platform 3.11). From the command line:
$ oc edit secret <my_custom_resource_name-credentials-secret>
-
From the OpenShift Container Platform web console, click the secret that includes your broker Custom Resource instance in its name. To see the encrypted user name and password values, click the YAML tab (OpenShift Container Platform 4.1) or
2.7. Broker deployment examples
2.7.1. Deploying clustered brokers
If there are two or more broker Pods running in your project, the Pods automatically form a broker cluster. A clustered configuration enables brokers to connect to each other and redistribute messages as needed, for load balancing.
The following procedure shows you how to deploy clustered brokers. By default, the brokers in this deployment use on demand load balancing, meaning that brokers will forward messages only to other brokers that have matching consumers.
Prerequisites
- A basic broker is already deployed. See Deploying a basic broker.
Procedure
-
In the
deploy/crs
directory of the Operator archive that you downloaded and extracted, open thebroker_v2alpha1_activemqartemis_cr.yaml
Custom Resource file. -
For a minimally-sized clustered deployment, ensure that the value of
deploymentPlan.size
is2
. At the command line, apply the change:
$ oc apply -f deploy/crs/broker_v2alpha1_activemqartemis_cr.yaml
In the OpenShift Container Platform web console, a second Pod starts in your project, for the additional broker that you specified in your CR. By default, the two brokers running in your project are clustered.
Open the Logs tab of each Pod. The logs show that OpenShift has established a cluster connection bridge on each broker. Specifically, the log output includes a line like the following:
targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@6f13fb88
2.7.2. Creating queues in a broker cluster
The following procedure shows you how to use a Custom Resource Definition (CRD) and example Custom Resource (CR) to add and remove a queue from a broker cluster deployed using an Operator.
Prerequisites
- You have already deployed a broker cluster. See Deploying clustered brokers.
Procedure
Deploy the addressing CRD.
$ oc create -f deploy/crds/broker_v2alpha1_activemqartemisaddress_crd.yaml
An example CR file,
broker_v2alpha1_activemqartemisaddress_cr.yaml
, was included in the Operator archive that you downloaded and extracted. The example Custom Resource includes the following:spec: # Add fields here spec: addressName: myAddress0 queueName: myQueue0 routingType: anycast
With your broker cluster already already deployed and running via the Operator, use the example Custom Resource to create an address on every running broker in your cluster.
$ oc create -f deploy/crs/broker_v2alpha1_activemqartemisaddress_cr.yaml
Deploying the example CR creates an address
myAddress0
with a queue namedmyQueue0
that has ananycast
routing type. This address is created on every running broker.NoteTo create multiple addresses and/or queues in your broker cluster, you need to create separate CR files and deploy them individually, specifying new address and/or queue names in each case.
NoteIf you add brokers to your cluster after deploying the addressing CR, the new brokers will not have the address you previously created. In this case, you need to delete the addresses and redeploy the addressing CR.
To delete queues created from the example CR, use the following command:
$ oc delete -f deploy/crs/broker_v2alpha1_activemqartemisaddress_cr.yaml
2.8. Migrating messages upon scaledown
To migrate messages upon scaledown of your broker deployment, use the main broker Custom Resource Definition (CRD) to enable message migration. The AMQ Broker Operator runs a dedicated scaledown controller to execute message migration when you scale down a clustered broker deployment.
With message migration enabled, the scaledown controller within the Operator detects shutdown of a broker Pod and starts a drainer Pod to execute message migration. The drainer Pod connects to one of the other live broker Pods in the cluster and migrates messages over to that live broker Pod. After migration is complete, the scaledown controller shuts down.
A scaledown controller operates only within a single OpenShift project. The controller cannot migrate messages between brokers in separate projects.
If you scale a broker deployment down to 0 (zero), message migration does not occur, since there is no running broker Pod to which the messaging data can be migrated. However, if you scale a deployment down to zero brokers and then back up to only some of the brokers that were in the original deployment, drainer Pods are started for the brokers that remain shut down.
The following example procedure shows the behavior of the scaledown controller.
Prerequisites
- You already have a basic broker deployment. See Deploying a basic broker.
- You should understand how message migration works. For more information, see Message migration.
Procedure
-
In the
deploy/crs
directory of the Operator repository that you originally downloaded and extracted, open the main broker CR,broker_v2alpha1_activemqartemis_cr.yaml
. In the main broker CR set
messageMigration
andpersistenceEnabled
totrue
.These settings mean that when you later scale down the size of your clustered broker deployment, the Operator automatically starts a scaledown controller and migrate messages to a broker Pod that is still running.
In your existing broker deployment, verify which Pods are running.
$ oc get pods
You see output that looks like the following.
activemq-artemis-operator-8566d9bf58-9g25l 1/1 Running 0 3m38s ex-aao-ss-0 1/1 Running 0 112s ex-aao-ss-1 1/1 Running 0 8s
The preceding output shows that there are three Pods running; one for the broker Operator itself, and a separate Pod for each broker in the deployment.
Log into each Pod and send some messages to each broker.
Supposing that Pod
ex-aao-ss-0
has a cluster IP address of172.17.0.6
, run the following command:$ /opt/amq-broker/bin/artemis producer --url tcp://172.17.0.6:61616 --user admin --password admin
Supposing that Pod
ex-aao-ss-1
has a cluster IP address of172.17.0.7
, run the following command:$ /opt/amq-broker/bin/artemis producer --url tcp://172.17.0.7:61616 --user admin --password admin
The preceding commands create a queue called
TEST
on each broker and add 1000 messages to each queue.
Scale the cluster down from two brokers to one.
-
Open the main broker CR,
broker_v2alpha1_activemqartemis_cr.yaml
. -
In the CR, set
deploymentPlan.size
to1
. At the command line, apply the change:
$ oc apply -f deploy/crs/broker_v2alpha1_activemqartemis_cr.yaml
You see that the Pod
ex-aao-ss-1
starts to shut down. The scaledown controller starts a new drainer Pod of the same name. This drainer Pod also shuts down after it migrates all messages from broker Podex-aao-ss-1
to the other broker Pod in the cluster,ex-aao-ss-0
.
-
Open the main broker CR,
-
When the drainer Pod is shut down, check the message count on the
TEST
queue of broker Podex-aao-ss-0
. You see that the number of messages in the queue is 2000, indicating that the drainer Pod successfully migrated 1000 messages from the broker Pod that shut down.
2.9. Managing the Broker Operator using the Operator Lifecycle Manager
2.9.1. Overview of the Operator Lifecycle Manager
In OpenShift Container Platform 4.0 and later, the Operator Lifecycle Manager (OLM) helps users install, update, and generally manage the lifecycle of all Operators and their associated services running across their clusters. It is part of the Operator Framework, an open source toolkit designed to manage Kubernetes native applications (Operators) in an effective, automated, and scalable way.
The OLM runs by default in OpenShift Container Platform 4.0, which aids cluster administrators in installing, upgrading, and granting access to Operators running on their cluster. The OpenShift Container Platform web console provides management screens for cluster administrators to install Operators, as well as grant specific projects access to use the catalog of Operators available on the cluster.
OperatorHub is the graphical interface that OpenShift cluster administrators use to discover, install, and upgrade Operators. With one click, these Operators can be pulled from OperatorHub, installed on the cluster, and managed by the OLM, ready for engineering teams to self-service manage the software in development, test, and production environments.
When you install the AMQ Broker Operator in OperatorHub, you can use the graphical interface to create various broker deployments, such as standalone and clustered brokers.
2.9.2. Installing the AMQ Broker Operator in OperatorHub
If you do not see the AMQ Broker Operator automatically available for use in OperatorHub, follow these instructions to manually install the Operator.
Procedure
- In your web browser, navigate to the AMQ Broker Software Downloads page.
-
In the Version drop-down box, ensure the value is set to the latest Broker version,
7.5.0
. Next to AMQ Broker 7.5 Operator Installation Files, click Download.
Download of the
amq-broker-operator-7.5.0-ocp-install-examples.zip
compressed archive automatically begins.When the download has completed, move the archive to your chosen installation directory. The following example moves the archive to a directory called
/broker/operator
.sudo mv amq-broker-operator-7.5.0-ocp-install-examples.zip /broker/operator
In your chosen installation directory, extract the contents of the archive. For example:
cd /broker/operator unzip amq-broker-operator-7.5.0-ocp-install-examples.zip
Log in to OpenShift Container Platform as a cluster administrator.
$ oc login -u system:admin
Deploy the AMQ Broker Operator source bundle from the
deploy
directory of the Operator archive that you downloaded and extracted.$ oc create -f deploy/catalog_resources/courier/amq-broker-operatorsource.yaml
After a few minutes, the AMQ Broker Operator is available in the OperatorHub section of the OpenShift Container Platform web console. You can then use the OperatorHub graphical interface to create various types of broker deployments.