This demonstration describes how to create a RabbitMQ cluster in Openshift.
-
OpenShift Container Platform v3.6 or newer (we're using this feature).
-
This example is configured to use a
PersistentVolume
for storing cluster and message data. Thus it is a requirement that Openshift is configured to support Persistent Volumes and that there are PVs with at leastReadWriteOnce
(RWO) access available. -
This example is also using the OpenShift Applier to build and deploy RabbitMQ. As a result you'll need to have ansible installed.
The openshift-applier will create the following OpenShift objects:
- A Project named
rabbitmq
- Two ImageStreams
rabbitmq
andubi
(see .openshift/templates/builds/template.yml and .openshift/templates/imagestreams/images.yml) - A BuildConfig named
rabbitmq
(see .openshift/templates/builds/template.yml) - A RoleBinding named
rabbitmq
(see .openshift/templates/deployments/template.yml) - A Service named
rabbitmq
(see .openshift/templates/deployments/template.yml) - A ConfigMap named
rabbitmq-config
(see .openshift/templates/configmaps/config.yml) - A StatefulSet named
rabbitmq
(see .openshift/templates/deployments/template.yml)
NAME | DESCRIPTION | VALUE |
---|---|---|
APPLICATION_NAME | The name for the application | rabbitmq |
CONTEXT_DIR | Path within Git project to build | rabbitmq |
ERLANG_VERSION | Erlang version to use | 22.1.4 |
FROM_IMAGE | Docker image to build from | ubi:7.7 |
RABBITMQ_VERSION | RabbitMQ version to build | 3.8.0 |
SOURCE_REPOSITORY_REF | Git branch/tag reference | master |
SOURCE_REPOSITORY_URL | Git source URI for application | https://github.com/redhat-cop/containers-quickstarts |
ERLANG_VERSION
& RABBITMQ_VERSION
are passed on to the buildconfig thus these versions can be controlled in the build.
This is the equivivalent of docker build --build-arg ERLANG_VERSION=19.3.6` to a docker build.
- Clone this repository:
git clone https://github.com/redhat-cop/containers-quickstarts
cd containers-quickstarts/rabbitmq
oc new-project rabbitmq
helm install rabbitmq chart
NOTE: This image is currently not compatible with https://github.com/bitnami/charts/tree/master/bitnami/rabbitmq but this might change in the future.
- Clone this repository:
git clone https://github.com/redhat-cop/containers-quickstarts
cd containers-quickstarts/rabbitmq
- Run
ansible-galaxy install -r requirements.yml --roles-path=roles
- Login to Openshift:
oc login -u <username> https://master.example.com:8443
- Run openshift-applier:
ansible-playbook -i .applier/ roles/openshift-applier/playbooks/openshift-cluster-seed.yml
$ oc get pod -n rabbitmq
NAME READY STATUS RESTARTS AGE
rabbitmq-0 1/1 Running 0 1m
rabbitmq-1 1/1 Running 0 1m
rabbitmq-1-build 0/1 Completed 0 1m
rabbitmq-2 1/1 Running 0 1m
$ oc rsh rabbitmq-1 rabbitmqctl cluster_status --formatter json | tail -1 | jq '{"alarms": .alarms,"running_nodes": .running_nodes,"versions": .versions}'
{
"alarms": [],
"running_nodes": [
"[email protected]",
"[email protected]",
"[email protected]"
],
"versions": {
"[email protected]": {
"erlang_version": "22.1.4",
"rabbitmq_version": "3.8.0"
},
"[email protected]": {
"erlang_version": "22.1.4",
"rabbitmq_version": "3.8.0"
},
"[email protected]": {
"erlang_version": "22.1.4",
"rabbitmq_version": "3.8.0"
}
}
}
This quickstart is using bats for unit and acceptance testing of the included Helm chart.
The unit tests will test features of the Helm chart and also requires yq.
bats test/unit
✓ configmap: three config files defined
✓ rolebinding: default serviceaccount
✓ rolebinding: custom serviceaccount
✓ service: enabled by default
✓ service: name match release name
...
✓ statefulset: default tolerations
✓ statefulset: custom tolerations
41 tests, 0 failures
The acceptance tests will deploy the RabbitMQ cluster using the Helm chart and assumes you have access to an OpenShift cluster (v3.11+) with at least self-provisioner access (it will create a new namespace). You will also need to install jq and at the moment you will need to use Bats from the master branch as the test require features added after the latest Bats' release.
bats test/acceptance
✓ rabbitmq/ha: should have 'hostname' package installed
✓ rabbitmq/ha: should have $LANG set to 'en_US.UTF-8'
✓ rabbitmq/ha: should not have any alarms
✓ rabbitmq/ha: fail if number of replicas aren't ready
✓ rabbitmq/ha: should run on different cluster nodes
✓ rabbitmq/ha: should have a three node cluster
6 tests, 0 failures
helm uninstall rabbitmq
or
oc delete project rabbitmq