we continue to work with the Kubernetes cluster prepared in the article
RabbitMQ cluster name and Namespace
RabbitMQ cluster name = rbmq-tst-clstr
RabbitMQ cluster Namespace = rbmq-tst-clstr-nmspc
Virtual Host is a very first object we should work with
kubectl apply -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Vhost
metadata:
name: rbmq-tst-clstr-vhost-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-vhost
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
Get a list of Virtual Hosts
yury@u2004s01:~$ kubectl get vhost -n rbmq-tst-clstr-nmspc
NAME AGE
rbmq-tst-clstr-vhost-mtdt 55s
kubectl delete -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Vhost
metadata:
name: rbmq-tst-clstr-vhost-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-vhost
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
rabbitmqctl set_vhost_limits -p vhost_name '{"max-connections": 256}'
rabbitmqctl set_vhost_limits -p vhost_name '{"max-queues": 1024}'
We could not find kubectl -command to set max-connections and(or) max-queues
Install krew which is unuseful
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
)
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
Install RabbitMQ Cluster Operator Plugin
kubectl krew install rabbitmq
Get cluster info with a Plugin
To test our plugin or make sure it works
yury@u2004s01:~$ kubectl rabbitmq -n rbmq-tst-clstr-nmspc get rbmq-tst-clstr
NAME READY STATUS RESTARTS AGE
pod/rbmq-tst-clstr-server-0 1/1 Running 0 18h
pod/rbmq-tst-clstr-server-1 1/1 Running 0 18h
NAME DATA AGE
configmap/rbmq-tst-clstr-plugins-conf 1 18h
configmap/rbmq-tst-clstr-server-conf 2 18h
NAME READY AGE
statefulset.apps/rbmq-tst-clstr-server 2/2 18h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/rbmq-tst-clstr ClusterIP 10.107.160.237 <none> 5672/TCP,15672/TCP,15692/TCP 18h
service/rbmq-tst-clstr-nodes ClusterIP None <none> 4369/TCP,25672/TCP 18h
NAME TYPE DATA AGE
secret/rbmq-tst-clstr-default-user Opaque 7 18h
secret/rbmq-tst-clstr-erlang-cookie Opaque 1 18h
It does not work
for u2004s01
kubectl rabbitmq -n rbmq-tst-clstr-nmspc set_vhost_limits rbmq-tst-clstr '{"max-connections": -1, "max-queues": -1}'
Management UI which is useful
Note: RabbitMQ is a statefull set, so we can use Management UI to change the settings inside the cluster
read the article Management UI
TLS is required in this case
kubectl exec which is useful
Note: RabbitMQ is a statefull set, so we can use rabbitmqctl to change the settings inside the cluster
for u2004s01
yury@u2004s01:~$ kubectl exec --stdin --tty rbmq-tst-clstr-server-0 -n rbmq-tst-clstr-nmspc -- /bin/bash
Defaulted container "rabbitmq" out of: rabbitmq, setup-container (init)
rabbitmq@rbmq-tst-clstr-server-0:/$ rabbitmqctl set_vhost_limits -p rbmq-tst-clstr-vhost '{"max-connections": 256}'
Setting vhost limits to "{"max-connections": 256}" for vhost "rbmq-tst-clstr-vhost" ...
rabbitmq@rbmq-tst-clstr-server-0:/$ rabbitmqctl set_vhost_limits -p rbmq-tst-clstr-vhost '{"max-queues": 100}'
Setting vhost limits to "{"max-queues": 100}" for vhost "rbmq-tst-clstr-vhost" ...
rabbitmq@rbmq-tst-clstr-server-0:/$ rabbitmqctl set_vhost_limits -p rbmq-tst-clstr-vhost '{"max-connections": 25, "max-queues": 30}'
Setting vhost limits to "{"max-connections": 25, "max-queues": 30}" for vhost "rbmq-tst-clstr-vhost" ...
rabbitmq@rbmq-tst-clstr-server-0:/$ exit
exit
read the article limitations
We must be careful with direct modification of the RabbitMQ cluster with kubectl exec
new testvhost has been created with rabbitmqctl add_vhost testvhost
but testvhost is not visible to Kubernetes
for u2004s01
yury@u2004s01:~$ kubectl exec --stdin --tty rbmq-tst-clstr-server-0 -n rbmq-tst-clstr-nmspc -- /bin/bash
Defaulted container "rabbitmq" out of: rabbitmq, setup-container (init)
rabbitmq@rbmq-tst-clstr-server-0:/$ rabbitmqctl add_vhost testvhost
Adding vhost "testvhost" ...
rabbitmq@rbmq-tst-clstr-server-0:/$ exit
exit
yury@u2004s01:~$ kubectl get vhost -n rbmq-tst-clstr-nmspc
NAME AGE
rbmq-tst-clstr-vhost-mtdt 16h
we do use spec.type as they recommend
Note that it's not recommended setting optional queue arguments on queues directly. Once set, queue properties cannot be changed. Use policies instead.
Most optional arguments can be dynamically changed after queue declaration but there are exceptions. For example, queue type (x-queue-type) and max number of queue priorities (x-max-priority) must be set at queue declaration time and cannot be changed after that.
for u2004s01 create a classic Queue with a name rabbit@rbmq-tst-clstr-server-0.rbmq-tst-clstr-nodes.rbmq-tst-clstr-nmspc
kubectl apply -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Queue
metadata:
name: rbmq-tst-clstr-queue-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-queue
type: classic
vhost: rbmq-tst-clstr-vhost
autoDelete: false
durable: true
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
yury@u2004s01:~$ kubectl get queues -n rbmq-tst-clstr-nmspc
NAME AGE
rbmq-tst-clstr-queue-mtdt 5m52s
kubectl delete -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Queue
metadata:
name: rbmq-tst-clstr-queue-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-queue
type: classic
vhost: rbmq-tst-clstr-vhost
autoDelete: false
durable: true
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
kubectl apply -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Policy
metadata:
name: rbmq-tst-clstr-queue-policy-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-queue-policy
vhost: rbmq-tst-clstr-vhost
pattern: "=rbmq-tst-clstr-queue"
applyTo: "queues"
definition:
max-length: 100
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
yury@u2004s01:~$ kubectl get policy -n rbmq-tst-clstr-nmspc
NAME AGE
rbmq-tst-clstr-queue-policy-mtdt 22m
kubectl delete -f- <<EOF
apiVersion: rabbitmq.com/v1beta1
kind: Policy
metadata:
name: rbmq-tst-clstr-queue-policy-mtdt
namespace: rbmq-tst-clstr-nmspc
spec:
name: rbmq-tst-clstr-queue-policy
vhost: rbmq-tst-clstr-vhost
pattern: "=rbmq-tst-clstr-queue"
applyTo: "queues"
definition:
max-length: 100
rabbitmqClusterReference:
name: rbmq-tst-clstr
EOF
The simplest method is as follows:
Open Management UI
Go to Admin/Policies -page
This page helps with a policy-names and policy-value-types for
Queues
Classic queues
Quorum queues
Exchanges
Federations
read the article Exchanges and Bindings
read the article API Reference: Exchange
read the article API Reference: Binding
Common case:
Declare Exchange of type=topic
Declare a list of bindings to any number of Queues we need
Create one (or more) consumers for each Queue of step 2
With Exchange we push the Message
Each Consumer (of step 3) pulls its copy of the Message
Disadvantage: A separate copy of the same Message will be created for each Queue of step 2
Users and User Permissions