RabbitMQ Cluster on kubernetes - Part 1
RabbitMQ Cluster on Kubernates
RabbitMQ is one of the most widely used open-source message brokers. It was originally based on the Advanced Message Queuing Protocol (AMQP).In the RabbitMQ architecture main components are Producer ,Exchange ,Queue and Consumer application.
In this tutorial, we will use Red Hat® OpenShift® version 4.6. OpenShift is an enterprise-ready Kubernetes container platform with full-stack automated operations to manage hybrid cloud and multi-cloud deployments. Same RabbitMQ cluster deployment we can use any kubernetes container platform.
We will basically deploy a RabbitMQ cluster, a producer application (.Net core application) which will produce messages to a specific queue on RabbitMQ cluster, a consumer application (.Net core application) which will consume messages from the queue. All the application deployed to the worker node, following diagram shows the overview of the rabbitmq cluster on the Openshift.
Deploy RabbitMQ Cluster
In here I will put every command that can run on both Kubernetes and openshift.
- let’s create a namespace or project either kubernetes or Openshift.
All resources in Kubernetes are started in a namespace. Unless one is specified. To have better control over the deployment process use the following command to create a distinct namespace.
kubectl create ns rabbitsoc create project rabbits
2. Download the yaml files to create the RabbitMQ cluster. Update namespace according to your project.
https://github.com/darshanadinushal/rabbitmq-cluster/blob/master/deployment/rabbitmq-cluster/rabbit-configmap.yamlhttps://github.com/darshanadinushal/rabbitmq-cluster/blob/master/deployment/rabbitmq-cluster/rabbit-rbac.yaml
https://github.com/darshanadinushal/rabbitmq-cluster/blob/master/deployment/rabbitmq-cluster/rabbit-secret.yaml
3. Get the Storage Class name and update the rabbit-statefulset.yaml ,there is a volumeClaimTemplates > storageClassName.
RabbitMQ requires using a Stateful Set to deploy a RabbitMQ cluster to Kubernetes. The Stateful Set ensures that the RabbitMQ nodes are deployed in order, one at a time. There are other, equally important reasons for using a Stateful Set instead of a Deployment: sticky identity, simple network identifiers, stable persistent storage and the ability to perform ordered rolling upgrades.
By using a StatefulSet as is intended for the case where Pods have persistent data that is associated with their "identity. If the RabbitMQ cluster down ,pods restart or pods failure Kubernetes will create new pods ,but having persistent storage rabbitmq queue messages will not delete.
kubectl get storageclass
oc get storageclass
Replace here
4. Deploy the cluster using yaml file.
Kubernetes:
kubectl create -n rabbits -f .\rabbit-rbac.yaml
kubectl create -n rabbits -f .\rabbit-configmap.yaml
kubectl create -n rabbits -f .\rabbit-secret.yaml
kubectl create -n rabbits -f .\rabbit-statefulset.yaml
Openshift:
oc create -n rabbits -f .\rabbit-rbac.yamloc create -n rabbits -f .\rabbit-configmap.yamloc create -n rabbits -f .\rabbit-secret.yaml
oc create -n rabbits -f .\rabbit-statefulset.yaml
5. Create route for the service to expose the rabbitMQ cluster to the Internet.
Openshift:
Kubernetes:
Download the yaml file and execute the following command to create route.
https://github.com/darshanadinushal/rabbitmq-cluster/blob/master/deployment/route-kubernetes.yaml
kubectl create -n rabbits -f .\route-kubernetes.yaml
6. Login to the RabbitMQ Cluster.
Login to the RabbitMQ cluster using user name and password.
Username : guest
Password : guest
After navigate to Admin tab, we can see the default user (“guest”) details who is having “administrator” privileges and below that we have Add a user panel to add new user.
After we click on “Add a user” panel, it will show the panel with different parameters to create a new user like as shown below.
If you observe above picture, we have a section called Tags. Here, Tags are the rights or privileges which we assigned while creating a user and we can set single or multiple privileges to a user based on our requirements. In case, if we want to multiple privileges, then set privileges as a comma (,) separated like administrator, management, etc. based on our requirements.
Following are the different type of privileges or rights which supported in management plugin while creating a new user in RabbitMQ.
Tag |
Description |
management |
If we set
this tag, the user can access management plugin. |
policymaker |
If we set
this tag, the user can access management plugin and manage policies and
parameters for the vhosts they have access to. |
monitoring |
If we set
this tag, the user can access management plugin and see all the connections
and channels as well as node-related information. |
administrator |
If we set
this tag, the user can do everything in management like manage users, vhosts,
permissions, close other user's connections, and manage policies and parameters
for all vhosts. |
After adding a user, you can see all the users in All users panel for that just expand it like as shown below.
To set a permission to access virtual hosts, just click on the username which we have created “adminuser” and go to Permissions panel which is just below to overview panel and click on Set permission button to set permissions like as shown below.
Now we will use newly created user (“adminuser”) details to login into RabbitMQ web management. Following is the snapshot of RabbitMQ web management plugin after logging with new user “adminuser”.
9. Automatic Synchronization.
rabbitmqctl set_policy ha-fed \
".*" '{"federation-upstream-set":"all", "ha-sync-mode":"automatic", "ha-mode":"nodes", "ha-params":["rabbit@rabbitmq-0.rabbitmq.rabbits.svc.cluster.local","rabbit@rabbitmq-1.rabbitmq.rabbits.svc.cluster.local","rabbit@rabbitmq-2.rabbitmq.rabbits.svc.cluster.local"]}' \
--priority 1 \
--apply-to queues
Summary
In this tutorial, you learned how to quickly deploy a RabbitMQ Cluster on kubernetes or OpenShift using yaml files. You have also gained access to the RabbitMQ management create new admin user and assign user privilege.
Comments
Post a Comment