rocketmq

by apecloud

Helm chartv1.2.0-alpha.0App 4.9.6Verified publisher

RocketMQ is a distributed messaging and streaming platform originally developed by Alibaba, featuring high throughput, low latency, and strong reliability for processing millions of messages per second.

About this chart

RocketMQ

Apache RocketMQ is a distributed messaging and streaming platform with low latency, high performance and reliability, trillion-level capacity and flexible scalability.

Features In KubeBlocks

Lifecycle Management

TopologyHorizontalscalingVertical scalingExpandvolumeRestartStop/StartConfigureExposeSwitchover
clusterYes (NameServer)YesYesYesYesYesYesN/A

Versions

Major VersionsDescription
4.x4.9.6

Prerequisites

  • Kubernetes cluster >= v1.21

  • kubectl installed, refer to K8s Install Tools

  • Helm, refer to Installing Helm

  • KubeBlocks installed and running, refer to Install Kubeblocks

  • RocketMQ 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 rocketmq cluster::

# cat examples/rocketmq/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  # The name of the RocketMQ cluster instance
  name: rocketmq-cluster
  # The namespace where the cluster will be deployed
  namespace: demo
spec:
  # Reference to the cluster definition that defines the cluster's behavior
  clusterDef: rocketmq
  # Specifies cluster topology defined in ClusterDefinition.Spec.topologies.
  # - `master-slave`
  topology: master-slave
  # 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
  # Component specifications - defines individual components of the cluster
  componentSpecs:
    # NameServer component - provides routing information for message producers and consumers
    - name: namesrv
      # Number of NameServer instances
      replicas: 1
      # Version of the RocketMQ NameServer
      serviceVersion: 4.9.6
      resources:
        limits:
          cpu: "2"
          memory: "2Gi"
        requests:
          cpu: "1"
          memory: "1Gi"
    # Exporter component - exposes metrics for monitoring
    - name: exporter
      replicas: 1
      # Version of the RocketMQ exporter
      serviceVersion: 0.0.3
      resources:
        limits:
          cpu: "1"
          memory: "1Gi"
        requests:
          cpu: "0.1"
          memory: "1Gi"
    # Dashboard component - provides web UI for cluster management
    - name: dashboard
      replicas: 1
      # Version of the RocketMQ dashboard
      serviceVersion: 2.0.1
      resources:
        limits:
          cpu: "1"
          memory: "1Gi"
        requests:
          cpu: "0.1"
          memory: "1Gi"
  # Shardings - defines horizontally sharded components (like brokers)
  shardings:
    - name: broker
      # Number of broker shards - each shard can have multiple replicas
      shards: 2
      template:
        # Template name for the broker instances
        name: rocketmq-broker
        # Number of replicas per shard (1 = master only, >1 = master with slaves)
        replicas: 2
        # Version of the RocketMQ broker
        serviceVersion: 4.9.6
        resources:
          limits:
            cpu: "2"
            memory: "4Gi"
          requests:
            cpu: "1"
            memory: "1Gi"
        # Persistent volume configuration for broker data storage
        volumeClaimTemplates:
          - name: data
            spec:
              # Volume access mode - ReadWriteOnce means single node read-write access
              accessModes:
                - ReadWriteOnce
              resources:
                requests:
                  # Storage size for each broker instance
                  storage: 20Gi
kubectl apply -f examples/rocketmq/cluster.yaml

This creates a RocketMQ cluster with four components: nameserver, broker (with sharding), exporter, and dashboard.

Horizontal scaling

Horizontal scaling for RocketMQ involves scaling the broker shards and nameserver replicas.

Scale-out NameServer by OpsRequest

Horizontal scaling out NameServer by adding ONE more replica:

# cat examples/rocketmq/scale-out-namesrv.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-name-server-scale-out
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: rocketmq-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: namesrv
    # 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/rocketmq/scale-out-namesrv.yaml

Scale-in NameServer by OpsRequest

Horizontal scaling in cluster by deleting ONE replica:

# cat examples/rocketmq/scale-in-namesrv.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-name-server-scale-in
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: rocketmq-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: namesrv
    # 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/rocketmq/scale-in-namesrv.yaml

On scale-in, the replica with the highest number (if not specified in particular) will be stopped and removed from the cluster.

Scale-in/out using Cluster API

Alternatively, you can update the replicas and shards field in cluster CR to your desired non-zero number.

apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: namesrv
      replicas: 3 # Update `replicas` to your desired number

[!NOTE] Horizontal scaling of Broker is not fully supported yet.

Vertical scaling

Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster

# cat examples/rocketmq/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-verticalscaling
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: rocketmq-cluster
  type: VerticalScaling
  # Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
  verticalScaling:
  - componentName: namesrv
    # 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/rocketmq/verticalscale.yaml

Scale-up/down using Cluster API

Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.

apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: namesrv
      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/rocketmq/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-volumeexpansion
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: rocketmq-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: namesrv
    # volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
    volumeClaimTemplates:
    - name: data
      storage: 30Gi

kubectl apply -f examples/rocketmq/volumeexpand.yaml

Volume expansion using Cluster API

Alternatively, you may update the volumeClaimTemplates.spec.resources.requests.storage field to the desired size.

apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  shardings:
    - name: broker
      shards: 3
      volumeClaimTemplates:
        - name: data
          spec:
            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/rocketmq/restart-namesrv.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-restart-namesrv
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: rocketmq-cluster
  type: Restart
  # Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
  restart:
    # Specifies the name of the Component.
  - componentName: namesrv

kubectl apply -f examples/rocketmq/restart-namesrv.yaml

Expose

Expose NameServer by OpsRequest

# cat examples/rocketmq/expose-enable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: rocketmq-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: rocketmq-cluster
  # Lists Expose objects, each specifying a Component and its services to be exposed.
  expose:
    # Specifies the name of the Component.
  - componentName: namesrv
    # 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: nameserver
          port: 9876
          targetPort: nameserver
      # 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/rocketmq/expose-enable.yaml

Expose SVC using Cluster API

Alternatively, you may expose service by updating spec.services

apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  services:
  - annotations:
      # aws annotations
      service.beta.kubernetes.io/aws-load-balancer-type: nlb  # Use Network Load Balancer
      service.beta.kubernetes.io/aws-load-balancer-internal: "true"  # or "false" for internet
    componentSelector: namesrv
    name: rocketmq-namesrv
    serviceName: rocketmq-namesrv
    spec:
      ports:
      - name: nameserver
        port: 9876
        protocol: TCP
        targetPort: nameserver
      type: LoadBalancer

If the service is of type LoadBalancer, please add annotations for cloud loadbalancer depending on the cloud provider you are using. Here list annotations for some cloud providers:

Cloud ProviderAnnotation KeyValueDescription
Alibaba Cloud`service.beta.kubernetes.i

Deploy rocketmq with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has rocketmq 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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartrocketmq is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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