MQTT Broker Storage Volumes in Kubernetes
Configure initial storage sizes for new deployments and resize existing broker volumes in Kubernetes environments.
The disk space required for MQTT brokers depends on your use case, particularly regarding the use of QoS levels greater than 0, retained messages, and message sizes. Since storage requirements cannot be perfectly predicted, you may need to resize existing volumes or configure appropriate initial sizes.
This document covers both configuring initial storage volume sizes and resizing existing volumes to increase available disk space with minimal service interruption.
The resizing procedure involves removing the StatefulSet, which leaves the broker cluster vulnerable to failures caused by cluster events or human error. Execute this procedure with great care and only in a stable cluster environment.
Configuring Initial Storage Volume Sizes
When deploying Connectware, you can configure the storage volume sizes for the MQTT broker through Helm values. The broker uses two volumes:
data
Stores retained messages, offline queues, and cluster metadata
global.broker.storage.data.size
1Gi
log
Stores log files
global.broker.storage.log.size
100Mi
Prerequisites
Helm version 3 is installed on your system
The Kubernetes command-line tool kubectl is configured and has access to the target installation
You know the name and namespace of your Connectware installation. See Obtaining the name, namespace, and version of your Connectware installation
The
values.yamlfile is available
Procedure
Configure the storage volume sizes by adding the appropriate Helm values to your
values.yamlfile:
Example
global:
broker:
storage:
data:
size: 5Gi
log:
size: 500MiApply the configuration changes using the
helm upgradecommand:
You cannot change the size of existing volumes through Helm configuration alone. To resize existing volumes, follow the procedure in the next section.
Resizing Existing Broker Storage Volumes
Use this procedure to increase the available disk space for existing broker volumes (PersistentVolumeClaims). This process requires pod restarts, which means clients will need to reconnect.
Prerequisites
kubectlaccess to the installation with the current context namespace set to the target namespace (kubectl config set-context --current --namespace <target-namespace>).A
StorageClassthat supports volume expansion. Verify this by runningkubectl get scand checking thatALLOWVOLUMEEXPANSIONshowstruefor the StorageClass used by the volumes.
Preparing the Broker Cluster
Ensure you have a healthy broker cluster of at least two pods. Run
kubectl get sts brokerand verify it showsREADY 2/2or higher with matching numbers on both sides of the slash.If you only have a single broker, scale the StatefulSet to two replicas:
Export the StatefulSet definition to a local file:
Resizing Volumes
Repeat this procedure for each broker pod in your cluster.
Delete the broker StatefulSet while leaving the pods as orphans:
Set the
$brokervariable to the pod name of the broker you want to resize (e.g.,broker-0):
Delete the broker pod:
Increase the PersistentVolumeClaims size. Replace
<size>with the desired Kubernetes quantity for the volume (e.g.,5Gi):
This example resizes the data volume:
If you also need to resize the log volume, repeat this step for the log PersistentVolumeClaims:
Wait until the PersistentVolumeClaims shows the correct capacity:
Recreate the StatefulSet:
Wait for the StatefulSet to recreate the missing pod. Monitor the status by running
kubectl get sts brokeruntil it showsREADY 2/2or higher with matching numbers on both sides of the slash.Verify that all cluster members show consistent cluster information:
The output should look similar to this:
Repeat this procedure for each additional broker pod until all volumes are resized.
Persisting Volume Changes for Future Deployments
After resizing volumes, update your Helm values to reflect the new sizes for future deployments and upgrades. This prevents future Helm upgrades from reverting the volume size.
Update the following fields in your
values.yamlfile based on the volumes you resized:
brokerdata-broker-*
global.broker.storage.data.size
brokerlog-broker-*
global.broker.storage.log.size
Apply the configuration changes via the
helm upgradecommand:
For more information, see Applying Helm Configuration Changes.
Deleting Broker Data Volumes
Deleting broker data volumes will remove all retained messages, offline client queues, and cluster metadata. This is typically done when decommissioning an installation or performing a clean reinstall.
This procedure permanently removes all broker data including retained messages, offline queues, and cluster state. This action cannot be undone. Ensure you have proper backups if you need to preserve any data.
Prerequisites
kubectlaccess to the installation with the current context namespace set to the target namespace.Confirmation that all data can be permanently deleted.
The broker StatefulSet should be scaled down or deleted before removing volumes.
Procedure
Stop the broker cluster by scaling the StatefulSet to zero replicas:
Wait for all broker pods to terminate:
List all broker-related PersistentVolumeClaims:
Delete the broker data volumes. This will remove all data volumes for all broker replicas:
Alternatively, you can delete specific volumes by name:
Verify that the PersistentVolumeClaims have been deleted:
Redeploying the Broker Cluster
If you plan to redeploy the broker cluster after deleting the data volumes, you can scale it back up with fresh storage:
The broker cluster will start with fresh, empty volumes and will need to be reconfigured with any required settings.
Cleaning Up Persistent Volumes
Depending on your storage configuration, the underlying PersistentVolumes might still exist after deleting the claims. To completely remove all storage:
List any remaining PersistentVolumes that were bound to the deleted claims:
If PersistentVolumes still exist with a
Retainreclaim policy, delete them manually:
PersistentVolumes with a Delete reclaim policy will be automatically removed when their corresponding PersistentVolumeClaim is deleted.
Last updated
Was this helpful?

