Skip to content

Commit ac49962

Browse files
authored
A few rabbitmqcluster examples (rabbitmq#181)
* a few rabbitmqcluster examples * typo
1 parent cbce6ec commit ac49962

File tree

17 files changed

+209
-0
lines changed

17 files changed

+209
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Custom Configuration Example
2+
3+
You can configure RabbitMQ cluster by setting `.spec.rabbitmq.additionalConfig`. It is a multi-line value that will be appended to the `rabbitmq.conf` generated by the operator.
4+
5+
You can deploy this example like this:
6+
7+
```shell
8+
kubectl apply -f rabbitmq.yaml
9+
```
10+
11+
And once deployed, you can check the complete `rabbitmq.conf` file like this:
12+
13+
```shell
14+
kubectl get -o yaml configmap custom-configuration-rabbitmq-server-conf
15+
```
16+
17+
Keep in mind that currently [RabbitMQ image](https://hub.docker.com/_/rabbitmq/) appends a few more lines to the config file and therefore some properties specified in `additionalConfig` could be overridden. This issue will be resolved in the future.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: rabbitmq.com/v1beta1
2+
kind: RabbitmqCluster
3+
metadata:
4+
name: custom-configuration
5+
spec:
6+
replicas: 1
7+
rabbitmq:
8+
additionalConfig: |
9+
log.console.level = debug
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pem
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Federation Over TLS Example
2+
3+
This is the a more complex example of deploying two `RabbitmqCluster`s and setting up federation between them. Upstream cluster has TLS enabled and therefore federation works over a TLS connection.
4+
5+
First, please follow [TLS example](../tls) to create a TLS secret. Once you have a secret, run the `setup.sh` script:
6+
7+
```shell
8+
./setup.sh
9+
```
10+
11+
The script will stop at some point and ask you to run `sudo kubefwd svc`. This is so that `rabbitmqadmin` can connect to the Management API and configure federation.
12+
13+
Therefore to use this script as-is, you need both [kubefwd](https://github.com/txn2/kubefwd) and [rabbitmqadmin](https://www.rabbitmq.com/management-cli.html) CLIs on your machine.
14+
15+
Learn [more about RabbitMQ Federation](https://www.rabbitmq.com/federation.html).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: rabbitmq.com/v1beta1
2+
kind: RabbitmqCluster
3+
metadata:
4+
name: downstream
5+
spec:
6+
replicas: 1
7+
rabbitmq:
8+
additionalPlugins:
9+
- rabbitmq_federation
10+
- rabbitmq_federation_management
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
kubectl apply -f upstream.yaml
4+
kubectl apply -f downstream.yaml
5+
6+
sleep 2
7+
8+
kubectl wait --for=condition=Ready pod/upstream-rabbitmq-server-0
9+
kubectl wait --for=condition=Ready pod/downstream-rabbitmq-server-0
10+
11+
UPSTREAM_USERNAME=$(kubectl get secret upstream-rabbitmq-admin -o jsonpath="{.data.username}" | base64 --decode)
12+
UPSTREAM_PASSWORD=$(kubectl get secret upstream-rabbitmq-admin -o jsonpath="{.data.password}" | base64 --decode)
13+
DOWNSTREAM_USERNAME=$(kubectl get secret downstream-rabbitmq-admin -o jsonpath="{.data.username}" | base64 --decode)
14+
DOWNSTREAM_PASSWORD=$(kubectl get secret downstream-rabbitmq-admin -o jsonpath="{.data.password}" | base64 --decode)
15+
16+
kubectl exec downstream-rabbitmq-server-0 -- rabbitmqctl set_parameter federation-upstream my-upstream "{\"uri\":\"amqps://${UPSTREAM_USERNAME}:${UPSTREAM_PASSWORD}@upstream-rabbitmq-client\",\"expires\":3600001}"
17+
18+
kubectl exec downstream-rabbitmq-server-0 -- rabbitmqctl set_policy --apply-to exchanges federate-me "^amq\." '{"federation-upstream-set":"all"}'
19+
20+
echo "**********************************************************"
21+
echo "* PLEASE RUN 'sudo kubefwd svc' TO START PORT FORWARDING *"
22+
echo "* and press ENTER when ready *"
23+
echo "**********************************************************"
24+
read
25+
26+
UPSTREAM_RABBITMQADMIN="rabbitmqadmin -U http://upstream-rabbitmq-client/ -u ${UPSTREAM_USERNAME} -p ${UPSTREAM_PASSWORD} -V /"
27+
DOWNSTREAM_RABBITMQADMIN="rabbitmqadmin -U http://downstream-rabbitmq-client/ -u ${DOWNSTREAM_USERNAME} -p ${DOWNSTREAM_PASSWORD} -V /"
28+
29+
$RABBITMQADMIN_UPSTREAM declare queue name=test.queue queue_type=quorum
30+
$RABBITMQADMIN_UPSTREAM declare binding source=amq.fanout destination=test.queue
31+
32+
$DOWNSTREAM_RABBITMQADMIN declare queue name=test.queue queue_type=quorum
33+
$DOWNSTREAM_RABBITMQADMIN declare binding source=amq.fanout destination=test.queue
34+
35+
$UPSTREAM_RABBITMQADMIN publish exchange=amq.fanout routing_key=test payload="hello, world"
36+
$DOWNSTREAM_RABBITMQADMIN get queue=test.queue ackmode=ack_requeue_false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: rabbitmq.com/v1beta1
2+
kind: RabbitmqCluster
3+
metadata:
4+
name: upstream
5+
spec:
6+
replicas: 1
7+
tls:
8+
secretName: tls-secret

docs/examples/hello-world/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Hello World Example
2+
3+
This is the simplest `RabbitmqCluster` definition. The only explicitly specified property is the name of the cluster. Everything else will be configured according to the Cluster Operator's defaults.
4+
5+
You can deploy this example like this:
6+
7+
```shell
8+
kubectl apply -f rabbitmq.yaml
9+
```
10+
11+
And once deployed, you can check what defaults were applied like this (`spec` section is the most important):
12+
13+
```shell
14+
kubectl get -o yaml rabbitmqclusters.rabbitmq.com hello-world
15+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: rabbitmq.com/v1beta1
2+
kind: RabbitmqCluster
3+
metadata:
4+
name: hello-world

docs/examples/plugins/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Plugins Example
2+
3+
You can enable RabbitMQ plugins by setting `.spec.rabbitmq.additionalPlugins`. It is a list value that will be appended to the list of plugins enabled by the operator that are considered essential and therefore always enabled.
4+
5+
You can deploy this example like this:
6+
7+
```shell
8+
kubectl apply -f rabbitmq.yaml
9+
```
10+
11+
And once deployed, you can check the list of enabled plugins like this:
12+
13+
```shell
14+
kubectl get -o yaml configmap plugins-rabbitmq-server-conf
15+
```
16+
17+
Changes to `additionalPlugins` do not require cluster restart. If you edit this field, Cluster Operator will run `rabbitmq-plugins` inside the running containers and enable/disable plugins without restarting pods.

0 commit comments

Comments
 (0)