rabbitmq
by apecloud
RabbitMQ is a reliable and mature messaging and streaming broker.
About this chart
RabbitMQ
RabbitMQ is an open-source and lightweight message broker which supports multiple messaging protocols.
Features In KubeBlocks
Lifecycle Management
| Topology | Horizontalscaling | Vertical scaling | Expandvolume | Restart | Stop/Start | Configure | Expose | Switchover |
|---|---|---|---|---|---|---|---|---|
| cluster | Yes | Yes | Yes | Yes | Yes | No | Yes | N/A |
Versions
| Major Versions | Description |
|---|---|
| 3.8 | 3.8.34 |
| 3.9 | 3.9.29 |
| 3.10 | 3.10.25 |
| 3.11 | 3.11.28 |
| 3.12 | 3.12.14 |
| 3.13 | 3.13.7 |
| 4.0 | 4.0.9 |
| 4.1 | 4.1.6 |
| 4.2 | 4.2.1 |
| 4.3 | 4.3.1 |
Prerequisites
-
Kubernetes cluster >= v1.21
-
kubectlinstalled, refer to K8s Install Tools -
Helm, refer to Installing Helm
-
KubeBlocks installed and running, refer to Install Kubeblocks
-
RabbitMQ Addon Enabled, refer to Install Addons
-
Create K8s Namespace
demo, to keep resources created in this tutorial isolated:kubectl create ns demo
Examples
Create
Create a rabbitmq cluster with 3 replicas:
# cat examples/rabbitmq/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: rabbitmq-cluster
namespace: demo
spec:
# Specifies the behavior when a Cluster is deleted.
# - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
# - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
# - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
terminationPolicy: Delete
# Specifies a list of ClusterComponentSpec objects used to define the individual components that make up a Cluster. This field allows for detailed configuration of each component within the Cluster.
# Note: `shardingSpecs` and `componentSpecs` cannot both be empty; at least one must be defined to configure a cluster.
# ClusterComponentSpec defines the specifications for a Component in a Cluster.
componentSpecs:
- name: rabbitmq
componentDef: rabbitmq
# The serviceVersion is used to determine the version of the Cluster. If the serviceVersion is not specified, the default value is the ServiceVersion defined in ComponentDefinition.
# ServiceVersion specifies the version of the Service expected to be
# provisioned by this Component.
# Valid options are: [3.8.34,3.9.29,3.10.25,3.11.28,3.12.14,3.13.7,4.0.9,4.1.6,4.2.1,4.3.1]
serviceVersion: 3.13.7
# Recommended to set `replicas` to [3,5,7]
# All data/state is replicated across all replicas.
replicas: 3
# Specifies the resources required by the Component.
resources:
limits:
cpu: "0.5"
memory: "0.5Gi"
requests:
cpu: "0.5"
memory: "0.5Gi"
# Specifies a list of PersistentVolumeClaim templates that define the storage
# requirements for the Component.
volumeClaimTemplates:
# Refers to the name of a volumeMount defined in
# `componentDefinition.spec.runtime.containers[*].volumeMounts
- name: data
spec:
# The name of the StorageClass required by the claim.
# If not specified, the StorageClass annotated with
# `storageclass.kubernetes.io/is-default-class=true` will be used by default
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# Set the storage size as needed
storage: 20Gi
kubectl apply -f examples/rabbitmq/cluster.yaml
[!Important] Unlike others, on creating the cluster, this example creates a ServiceAccount, Role, and RoleBinding for the RabbitMQ cluster. RabbitMQ needs
peer discoveryrole to create events and get endpoints. This is essential for discovering other RabbitMQ nodes and forming a cluster. WhenPulicyRuleAPI is ready, rules defined in theRolecan be defined in theComponentDefintion.Spec.PolicyRule. Such that KubeBlocks will automatically create and manage theRoleandRoleBindingfor the component.
Horizontal scaling
[!Important] RabbitMQ quorum queue are designed based on the Raft consensus algorithm. Make sure to have an odd number of replicas, such as 3, 5, 7, to avoid split-brain scenarios, after scaling out/in the cluster.
Scale-out
Horizontal scaling out cluster by adding ONE more replica:
# cat examples/rabbitmq/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-scale-out
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: rabbitmq
# Specifies the replica changes for scaling out components
scaleOut:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/rabbitmq/scale-out.yaml
Scale-in
Horizontal scaling in cluster by deleting ONE replica:
# cat examples/rabbitmq/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-scale-in
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: HorizontalScaling
# Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
horizontalScaling:
# Specifies the name of the Component.
- componentName: rabbitmq
# Specifies the replica changes for scaling out components
scaleIn:
# Specifies the replica changes for the component.
# add one more replica to current component
replicaChanges: 1
kubectl apply -f examples/rabbitmq/scale-in.yaml
On scale-in, the replica with the highest number (if not specified in particular) will be stopped, removed and be forget_cluster_node from the cluster.
Scale-in/out using Cluster API
Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.
spec:
componentSpecs:
- name: rabbitmq
componentDef: rabbitmq
replicas: 3 # Update `replicas` to your desired number
Vertical scaling
Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster
# cat examples/rabbitmq/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-verticalscaling
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: VerticalScaling
# Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
verticalScaling:
- componentName: rabbitmq
# VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
requests:
cpu: '1'
memory: 1Gi
limits:
cpu: '1'
memory: 1Gi
kubectl apply -f examples/rabbitmq/verticalscale.yaml
Scale-up/down using Cluster API
Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.
spec:
componentSpecs:
- name: rabbitmq
componentDef: rabbitmq
replicas: 3
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "2Gi" # Update the resources to your need.
limits:
cpu: "2" # Update the resources to your need.
memory: "4Gi" # Update the resources to your need.
Expand volume
[!NOTE] Make sure the storage class you use supports volume expansion.
Check the storage class with following command:
kubectl get storageclass
If the ALLOWVOLUMEEXPANSION column is true, the storage class supports volume expansion.
To increase size of volume storage with the specified components in the cluster
Increase size of volume storage with the specified components in the cluster
# cat examples/rabbitmq/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-volumeexpansion
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: VolumeExpansion
# Lists VolumeExpansion objects, each specifying a component and its corresponding volumeClaimTemplates that requires storage expansion.
volumeExpansion:
# Specifies the name of the Component.
- componentName: rabbitmq
# volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
volumeClaimTemplates:
- name: data
storage: 30Gi
kubectl apply -f examples/rabbitmq/volumeexpand.yaml
Volume expansion using Cluster API
Alternatively, you may update the spec.componentSpecs.volumeClaimTemplates.spec.resources.requests.storage field to the desired size.
spec:
componentSpecs:
- name: rabbitmq
componentDef: rabbitmq
replicas: 3
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# specify new size, and make sure it is larger than the current size
storage: 30Gi
Restart
Restart the specified components in the cluster:
# cat examples/rabbitmq/restart.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-restart
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: Restart
# Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
restart:
# Specifies the name of the Component.
- componentName: rabbitmq
kubectl apply -f examples/rabbitmq/restart.yaml
Stop
Stop the cluster and release all the pods of the cluster, but the storage will be reserved
# cat examples/rabbitmq/stop.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-stop
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: Stop
kubectl apply -f examples/rabbitmq/stop.yaml
Start
Start the stopped cluster
# cat examples/rabbitmq/start.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-start
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
type: Start
kubectl apply -f examples/rabbitmq/start.yaml
Expose
Enable
# cat examples/rabbitmq/expose-enable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: rabbitmq-expose-enable
namespace: demo
spec:
# Specifies the type of this operation.
type: Expose
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: rabbitmq-cluster
# Lists Expose objects, each specifying a Component and its services to be exposed.
expose:
# Specifies the name of the Component.
- componentName: rabbitmq
# Specifies a list of OpsService. When an OpsService is exposed, a corresponding ClusterService will be added to `cluster.spec.services`.
services:
- name: internet
# Determines how the Service is exposed. Defaults to 'ClusterIP'.
# Valid options are `ClusterIP`, `NodePort`, and `LoadBalancer`.
serviceType: LoadBalancer
ports:
- name: managment
port: 15672
targetPort: management
# Contains cloud provider related parameters if ServiceType is LoadBalancer.
# [NOTE] Following is an example for Aliyun ACK, please adjust the following annotations as needed.
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-charge-type: ""
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small
# Indicates whether the services will be exposed. 'Enable' exposes the services. while 'Disable' removes the exposed Service.
switch: Enable
kubectl apply -f examples/rabbitmq/expose-enable.yaml
Disable
# cat examples/rabbitmq/expose-disable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
m
Deploy rabbitmq with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has rabbitmq on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartrabbitmq is pinned at v1.2.0-alpha.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply