Configuring Environment Variables in HiveMQ Platform using Helm
This article guides you through the process of configuring custom environment variables for HiveMQ nodes deployed using the hivemq/hivemq-platform
Helm chart on Kubernetes.
Prerequisites:
A running Kubernetes cluster (e.g., Minikube, GKE, EKS, AKS, etc.)
Helm 3 installed and configured
Access to a container registry if using a private image
A working HiveMQ Platform Helm deployment setup (
hivemq/hivemq-platform
chart installed or ready for deployment)
Instructions
1. Prepare values.yaml
HiveMQ platform supports setting custom envronment variables. To know more about what all configurations are supported please check out default hivemq-platform values.yaml.
Edit or create a values.yaml
file for your HiveMQ deployment. To create you can use following command:
helm repo update
helm show values hivemq/hivemq-platform > values.yaml
Add the desired environment variables under the nodes.env
section:
nodes:
...
env:
- name: CUSTOM_ENV_VAR
value: some-value
...
HiveMQ Platform also supports loading envoronment variables using Kubernet Secrets and ConfigMaps.
Here are the steps to configure it.
Create Secret and ConfigMap (Skip this step if you already has Secret and ConfigMap created ): Refer following commands to create them.
# Create a secret kubectl create secret generic my-secret \ --from-literal=my-secret-key=secretValue # Create a config map kubectl create configmap my-config-map \ --from-literal=my-configmap-key=configValue
Configure env variables to load from Secret and ConfigMap:
nodes: ... env: - name: SECRET_ENV_VAR valueFrom: secretKeyRef: name: my-secret key: my-secret-key optional: false - name: CM_ENV_VAR valueFrom: configMapKeyRef: name: my-config-map key: my-configmap-key optional: true ...
2. Deploy or Upgrade HiveMQ using Helm
Use Helm to deploy or update your HiveMQ platform with the modified configuration:
helm upgrade --install hivemq hivemq/hivemq-platform \
-n <namespace> \
-f values.yaml
Replace
namespace
with your actual Kubernetes namespace.
3. Verify the Deployment
After the upgrade or install completes:
Check that your HiveMQ pods are running:
kubectl get pods -n <namespace>
Validate that the environment variables are set:
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh -c "printenv | grep ENV_VAR"
Setting Environment Variables via Helm CLI: Refer following example:
helm upgrade --install hivemq hivemq/hivemq-platform \ --namespace <namespace> \ --set 'nodes.env[0].name=CUSTOM_ENV_VAR' \ --set 'nodes.env[0].value=static-value' \ --set 'nodes.env[1].name=SECRET_ENV_VAR' \ --set 'nodes.env[1].valueFrom.secretKeyRef.name=my-secret' \ --set 'nodes.env[1].valueFrom.secretKeyRef.key=my-secret-key' \ --set 'nodes.env[2].name=CM_ENV_VAR' \ --set 'nodes.env[2].valueFrom.configMapKeyRef.name=my-config-map' \ --set 'nodes.env[2].valueFrom.configMapKeyRef.key=my-configmap-key'