Setting Up a HiveMQ Cluster with StatefulSet and Persistent Volumes in Kubernetes

This article provides a step-by-step guide on deploying a HiveMQ broker with StatefulSet resources and utilizing persistent volumes (PVs) for storage. By leveraging the HiveMQ operator and the StatefulSet controller, you can ensure seamless deployment, scaling, and data persistence within your HiveMQ cluster

We also have a comprehensive blog post that provides detailed instructions on deploying a HiveMQ cluster using StatefulSets on AKS (Azure Kubernetes Service)

Prerequisites

  • Running Kubernetes cluster version 1.18.0 or higher on the cloud provider of your choice

  • Helm version 3 or higher (to deploy with the HiveMQ Helm Chart)

  • Kubernetes command line tool kubectl

 Instructions

  1. Edit the custom values.yaml (myCustomValues.yaml) to configure the StatefulSet controller. Specify the desired StatefulSet template file (cluster-stateful-set.yaml) within the controllerTemplate field

    1. hivemq: nodeCount: 2 cpu: 4 memory: 4Gi controllerTemplate: cluster-stateful-set.yaml
  2. Add a persistent volume for the data folder in the HiveMQ configuration. Update the values.yaml file with the appropriate volume claim templates.

    1. hivemq: nodeCount: 2 cpu: 4 memory: 4Gi controllerTemplate: cluster-stateful-set.yaml volumeClaimTemplates: - kind: PersistentVolumeClaim apiVersion: v1 metadata: name: data spec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi volumeMode: Filesystem
  3. Deploy the HiveMQ cluster using Helm. Execute the following command, providing your custom values file.

    1. helm upgrade --install myhivemq hivemq/hivemq-operator -f myCustomValues.yaml
  4. Verify the successful creation of persistent volumes as specified in your values file. Use the following command:

By following this guide, you can set up a HiveMQ cluster utilizing StatefulSet resources and persistent volumes for data storage. This ensures seamless deployment, scaling, and reliable data persistence within your HiveMQ environment.

 Related articles