Connect your first client
Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.
This guide covers deploying a TBMQ cluster on Azure Kubernetes Service (AKS) with the official Helm chart.
The chart deploys only TBMQ: two broker nodes and two Integration Executors. PostgreSQL, Kafka, and a Redis-compatible cache run separately. This guide deploys them in the cluster with CrunchyData PGO, Strimzi, and Valkey; you can use Azure Database for PostgreSQL and Azure Managed Redis instead. Web traffic goes through an Azure Application Gateway, which the AKS ingress add-on configures, and MQTT traffic through an Azure Load Balancer.
AKS cluster · TBMQ Helm chart
Dependencies
Load balancer ports
Install the following tools:
Your Azure account needs permission to create resource groups, virtual networks, and AKS clusters, and to assign roles on the virtual network, for example the Owner role on the subscription. To use the managed services, it also needs permission to create them.
Sign in and select the subscription to deploy into:
az loginRegister the resource providers for AKS and its network. A provider registers once per subscription; the command returns at once for those that already are:
for ns in Microsoft.ContainerService Microsoft.Network; do az provider register --namespace $ns --waitdoneThe commands in this guide read these variables. Set them in the shell you run the guide from; if you open a new shell, set them again:
export AKS_RESOURCE_GROUP=TBMQResourcesexport AKS_LOCATION=eastusexport AKS_GATEWAY=tbmq-gatewayexport TB_CLUSTER_NAME=tbmq-clusterexport TB_DATABASE_NAME=tbmq-dbexport TB_REDIS_NAME=tbmq-cacheecho "Resource group: $AKS_RESOURCE_GROUP, region: $AKS_LOCATION"Where:
AKS_RESOURCE_GROUP: the resource group that holds every resource of this guide.AKS_LOCATION: the Azure region. List the regions with az account list-locations -o table.AKS_GATEWAY: the name of the Application Gateway that the ingress add-on creates.TB_CLUSTER_NAME: the name of the AKS cluster.TB_DATABASE_NAME and TB_REDIS_NAME: the names of the PostgreSQL server and the Redis cache. You need them only if
you use Azure managed services.Create the resource group and a virtual network. The aks subnet holds the AKS nodes and pods; the postgres and
endpoints subnets are for the managed services, if you use them:
az group create --name $AKS_RESOURCE_GROUP --location $AKS_LOCATION
az network vnet create --resource-group $AKS_RESOURCE_GROUP --name tbmq-vnet \ --address-prefixes 10.10.0.0/16 \ --subnet-name aks --subnet-prefixes 10.10.0.0/20
az network vnet subnet create --resource-group $AKS_RESOURCE_GROUP --vnet-name tbmq-vnet \ --name postgres --address-prefixes 10.10.17.0/24 \ --delegations Microsoft.DBforPostgreSQL/flexibleServers
az network vnet subnet create --resource-group $AKS_RESOURCE_GROUP --vnet-name tbmq-vnet \ --name endpoints --address-prefixes 10.10.18.0/24Create a cluster with three Standard_D4s_v6 nodes, one in each availability zone of the region, and the
Application Gateway ingress add-on,
which creates the gateway in a new 10.10.16.0/24 subnet. TBMQ and the dependencies this guide deploys share these
nodes:
export AKS_SUBNET_ID=$(az network vnet subnet show --resource-group $AKS_RESOURCE_GROUP \ --vnet-name tbmq-vnet --name aks --query id -o tsv)
az aks create --resource-group $AKS_RESOURCE_GROUP \ --name $TB_CLUSTER_NAME \ --vnet-subnet-id $AKS_SUBNET_ID \ --network-plugin azure \ --enable-addons ingress-appgw \ --appgw-name $AKS_GATEWAY \ --appgw-subnet-cidr 10.10.16.0/24 \ --node-vm-size Standard_D4s_v6 \ --node-count 3 \ --zones 1 2 3This takes about 10 minutes. To size the nodes for production, change --node-vm-size and --node-count; see
VM sizes.
If the command fails with a quota error, the subscription’s vCPU quota for the VM family or the region is too low:
request an increase
or choose another region. If the region has no availability zones, drop --zones.
Add the cluster to your kubeconfig and switch the current context to it:
az aks get-credentials --resource-group $AKS_RESOURCE_GROUP --name $TB_CLUSTER_NAMEkubectl get nodeshelm repo add tbmq-helm-chart https://helm.thingsboard.io/tbmqhelm repo updateCreate a namespace for TBMQ and its dependencies:
kubectl create namespace tbmqEvery command in this guide passes -n tbmq.
The chart doesn’t include PostgreSQL, Kafka, or a Redis-compatible cache. Any instances that TBMQ can reach work. This section deploys a small set in the cluster; size it for your load before production. To use Azure Database for PostgreSQL and Azure Managed Redis instead, deploy only Kafka here, then continue with Use Azure managed services.
Install the CrunchyData PGO operator and wait for it:
helm install pgo oci://registry.developers.crunchydata.com/crunchydata/pgo \ --version 6.0.1 -n tbmqkubectl wait --for=condition=Ready pod -l postgres-operator.crunchydata.com/control-plane=pgo \ -n tbmq --timeout=180sCreate a PostgreSQL 17 cluster with the thingsboard_mqtt_broker database:
cat <<'EOF' | kubectl apply -n tbmq -f -apiVersion: postgres-operator.crunchydata.com/v1beta1kind: PostgresClustermetadata: name: tbmq-dbspec: postgresVersion: 17 instances: - name: instance1 replicas: 1 dataVolumeClaimSpec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 10Gi users: - name: postgres databases: - thingsboard_mqtt_broker backups: pgbackrest: repos: - name: repo1 volume: volumeClaimSpec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 10GiEOFWait for the database pod. PGO creates it a few seconds after the manifest is applied, so the first command waits for the pod to exist:
until kubectl get pod -n tbmq -l postgres-operator.crunchydata.com/data=postgres 2>/dev/null | grep -q tbmq-db; do sleep 3; donekubectl wait --for=condition=Ready pod -l postgres-operator.crunchydata.com/data=postgres \ -n tbmq --timeout=300sPGO serves the database at tbmq-db-primary:5432 and stores the generated password in the Secret
tbmq-db-pguser-postgres, key password.
Install the Strimzi operator and wait for it:
helm repo add strimzi https://strimzi.io/charts/helm repo updatehelm install strimzi strimzi/strimzi-kafka-operator --version 0.50.0 -n tbmqkubectl wait --for=condition=Ready pod -l name=strimzi-cluster-operator -n tbmq --timeout=180sCreate a three-node Kafka 4.0 cluster in KRaft mode:
cat <<'EOF' | kubectl apply -n tbmq -f -apiVersion: kafka.strimzi.io/v1kind: KafkaNodePoolmetadata: name: combined labels: strimzi.io/cluster: tbmq-kafkaspec: replicas: 3 roles: - controller - broker storage: type: jbod volumes: - id: 0 type: persistent-claim size: 10Gi deleteClaim: false resources: requests: memory: "2Gi" cpu: "500m" limits: memory: "2Gi" cpu: "1"---apiVersion: kafka.strimzi.io/v1kind: Kafkametadata: name: tbmq-kafka annotations: strimzi.io/node-pools: enabled strimzi.io/kraft: enabledspec: kafka: version: 4.0.0 metadataVersion: "4.0" listeners: - name: plain port: 9092 type: internal tls: false config: auto.create.topics.enable: false default.replication.factor: 2 offsets.topic.replication.factor: 3 transaction.state.log.replication.factor: 3 transaction.state.log.min.isr: 2 entityOperator: topicOperator: {} userOperator: {}EOFWait for the cluster; this takes a few minutes:
kubectl wait kafka/tbmq-kafka --for=condition=Ready -n tbmq --timeout=600sKafka is reachable at tbmq-kafka-kafka-bootstrap:9092.
Install a standalone Valkey without a password and wait for it:
helm repo add valkey https://valkey.io/valkey-helm/helm repo updatehelm install valkey valkey/valkey --version 0.9.3 -n tbmqkubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=valkey -n tbmq --timeout=180sValkey is reachable at valkey:6379.
To use Azure Database for PostgreSQL and Azure Managed Redis instead of the in-cluster PostgreSQL and Valkey, create them in the cluster’s virtual network, as described in Create the Azure managed services of the Azure cluster setup guide. Register their resource providers first:
for ns in Microsoft.DBforPostgreSQL Microsoft.Cache; do az provider register --namespace $ns --waitdoneThe commands there read the environment variables you defined above. Once the services are ready, get the PostgreSQL host name, and the Redis host name and access key:
az postgres flexible-server show --resource-group $AKS_RESOURCE_GROUP --name $TB_DATABASE_NAME \ --query fullyQualifiedDomainName -o tsvaz redisenterprise show --resource-group $AKS_RESOURCE_GROUP --name $TB_REDIS_NAME \ --query hostName -o tsvaz redisenterprise database list-keys --resource-group $AKS_RESOURCE_GROUP \ --cluster-name $TB_REDIS_NAME --query primaryKey -o tsvCreate Secrets for the PostgreSQL password and the Redis access key in the tbmq namespace:
kubectl create secret generic tbmq-db-secret -n tbmq --from-literal=password='YOUR_DB_PASSWORD'kubectl create secret generic tbmq-redis-secret -n tbmq --from-literal=password='YOUR_REDIS_ACCESS_KEY'Then set the host names in Connect to dependencies instead of the in-cluster values:
postgresql: host: "tbmq-db.postgres.database.azure.com" port: 5432 database: "thingsboard_mqtt_broker" username: "tbmqadmin" existingSecret: "tbmq-db-secret" existingSecretPasswordKey: "password"
kafka: bootstrapServers: "tbmq-kafka-kafka-bootstrap:9092"
redis: connectionType: "standalone" host: "tbmq-cache.eastus.redis.azure.net" port: 10000 usePassword: true existingSecret: "tbmq-redis-secret" existingSecretPasswordKey: "password"Azure Managed Redis accepts only TLS connections. In the same step, also enable TLS in customEnv of the tbmq
section. TBMQ verifies the cache’s certificate against the CA certificates of its container image, which include the
roots that Azure certificates chain to:
tbmq: customEnv: REDIS_SSL_ENABLED: "true" REDIS_SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt"For all postgresql, kafka, and redis keys, see the
connection settings
in the chart documentation.
Export the chart’s default values to a values.yaml file:
helm show values tbmq-helm-chart/tbmq-cluster > values.yamlThe file pins the chart defaults, including the TBMQ image tags. Keep it: you edit and reuse it on every upgrade.
In values.yaml, find the postgresql, kafka, and redis sections and set these keys to point at the services from
the previous section:
postgresql: host: "tbmq-db-primary" port: 5432 database: "thingsboard_mqtt_broker" username: "postgres" existingSecret: "tbmq-db-pguser-postgres" existingSecretPasswordKey: "password"
kafka: bootstrapServers: "tbmq-kafka-kafka-bootstrap:9092"
redis: connectionType: "standalone" host: "valkey" port: 6379 usePassword: falseredis.connectionType defaults to cluster, so change it for a single Valkey node.
If you use Azure managed services, set the postgresql and redis values from
Use Azure managed services instead, and add the Redis TLS settings from the same section
to customEnv of the tbmq section. Without them, the broker nodes can’t connect to Redis.
Set the load balancer type to azure:
loadbalancer: type: "azure"The chart then creates two internet-facing load balancers:
| Load balancer | Kubernetes resource | Ports |
|---|---|---|
| Application Gateway | Ingress my-tbmq-cluster-http-lb |
80 (HTTP); 443 (HTTPS) with HTTPS enabled |
| Azure Load Balancer | Service my-tbmq-cluster-mqtt-lb |
1883 (MQTT), 8084 (MQTT over WebSockets), 8883 (MQTTS), 8085 (MQTT over secure WebSockets) |
The azure type needs chart version 2.3.2 or later; with earlier versions, helm install fails with
spec.ingressClassName: Invalid value: "azure/application-gateway".
The Azure Load Balancer passes TCP through to TBMQ unchanged, so it can’t terminate TLS. MQTTS and secure WebSockets work once TBMQ terminates TLS itself, with mutual TLS.
The Application Gateway terminates HTTPS with a certificate that you upload to it. Prepare the certificate of your domain and its private key as a password-protected PFX file, then add it to the gateway. The ingress add-on creates the gateway in the cluster’s node resource group:
az network application-gateway ssl-cert create \ --resource-group $(az aks show --resource-group $AKS_RESOURCE_GROUP --name $TB_CLUSTER_NAME \ --query nodeResourceGroup -o tsv) \ --gateway-name $AKS_GATEWAY \ --name TBMQHTTPSCert \ --cert-file YOUR_CERT.pfx \ --cert-password YOUR_CERT_PASSWORDEnable HTTPS in values.yaml, with the certificate’s name in the gateway:
loadbalancer: type: "azure" http: enabled: true ssl: enabled: true certificateRef: "TBMQHTTPSCert"The gateway serves HTTPS on 443 and redirects HTTP on 80 to HTTPS. After installing, point your domain at the
gateway’s address, shown in Validate HTTP access, with a DNS A record.
With mutual TLS, the Azure Load Balancer forwards ports 8883 and 8085 unchanged, and TBMQ terminates TLS itself.
This also supports
X.509 certificate authentication.
Create a Secret with the server certificate chain and its private key, in PEM format:
kubectl create secret generic tbmq-mqtts -n tbmq \ --from-file=server.pem=server-chain.pem \ --from-file=mqttserver_key.pem=server.keyEnable mutual TLS in values.yaml:
loadbalancer: type: "azure" mqtt: enabled: true mutualTls: enabled: true existingSecretName: "tbmq-mqtts"This enables MQTTS on 8883. To also serve MQTT over secure WebSockets on 8085 with the same certificate, add to
customEnv of the tbmq section:
tbmq: customEnv: LISTENER_WSS_ENABLED: "true" LISTENER_WSS_PEM_CERT: "/ssl-config/server.pem" LISTENER_WSS_PEM_KEY: "/ssl-config/mqttserver_key.pem"For a password-protected key and the other options, see mutual TLS in the chart documentation.
From the directory with your values.yaml, install the chart:
helm install my-tbmq-cluster tbmq-helm-chart/tbmq-cluster -n tbmq \ -f values.yaml \ --set installation.installDbSchema=truemy-tbmq-cluster is the Helm release name. It prefixes every resource the chart creates, and later helm commands
refer to it.
Helm runs a one-time install pod that creates the database schema and returns when the pod succeeds, usually within a minute:
NAME: my-tbmq-clusterNAMESPACE: tbmqSTATUS: deployedREVISION: 1...The broker pods start after the schema exists. Wait until they are ready:
kubectl rollout status statefulset/my-tbmq-cluster-tbmq-node -n tbmq --timeout=600sGet the address of the Application Gateway:
kubectl get ingress my-tbmq-cluster-http-lb -n tbmqNAME CLASS HOSTS ADDRESS PORTS AGEmy-tbmq-cluster-http-lb azure-application-gateway * 20.56.253.254 80 2mOpen http://{ADDRESS} in your browser, or your domain over HTTPS if you enabled it, and sign in as System
Administrator:
sysadmin@thingsboard.orgsysadminChange the password after the first sign-in.
Get the address of the Azure Load Balancer:
kubectl get svc my-tbmq-cluster-mqtt-lb -n tbmqNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEmy-tbmq-cluster-mqtt-lb LoadBalancer 10.0.224.65 50.85.145.252 1883:31320/TCP,8084:30819/TCP,8883:31462/TCP,8085:31172/TCP 2mMQTT clients connect to EXTERNAL-IP on port 1883, and MQTT over WebSockets on port 8084.
To check the broker end to end, publish and subscribe with the
Mosquitto clients. A new
installation has one MQTT credential, TBMQ WebSockets MQTT Credentials: username tbmq_websockets_username and no
password. In one terminal, subscribe:
mosquitto_sub -h {EXTERNAL-IP} -p 1883 -u tbmq_websockets_username -t 'tbmq/demo/#' -v -q 1In another, publish:
mosquitto_pub -h {EXTERNAL-IP} -p 1883 -u tbmq_websockets_username -t 'tbmq/demo/hello' -m 'hello from aks' -q 1The subscriber prints tbmq/demo/hello hello from aks. A client that connects without a username is refused as not
authorized, because MQTT Basic authentication is enabled by default. To create your own credentials, see
MQTT client credentials.
List the TBMQ pods:
kubectl get pods -n tbmq -l 'app in (my-tbmq-cluster-tbmq-node,my-tbmq-cluster-tbmq-ie,install-job)'View the logs of a broker node:
kubectl logs -f my-tbmq-cluster-tbmq-node-0 -n tbmqIf helm install fails with failed post-install, the schema install did not succeed. Read the install pod’s logs:
kubectl logs my-tbmq-cluster-install-pod -n tbmqIf applying the Kafka manifest fails with no matches for kind "KafkaNodePool" in version "kafka.strimzi.io/v1", the
cluster has the resource definitions of an older Strimzi release, which helm install doesn’t upgrade. Replace them
with the definitions of Strimzi 0.50.0, then apply the manifest again:
kubectl apply --server-side --force-conflicts \ -f https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.50.0/strimzi-crds-0.50.0.yamlBroker pods that stay in Init:0/1 are waiting for the schema. For the common causes and fixes, see
Troubleshooting the install
in the chart documentation.
With Azure managed services, connection errors to PostgreSQL or Redis in the broker logs mean a wrong host name, or a
private DNS zone that isn’t linked to tbmq-vnet. Redis authentication errors mean the tbmq-redis-secret Secret holds
a wrong access key.
If the Ingress ADDRESS or the Service EXTERNAL-IP stays empty, its events give the reason. The ingress add-on logs
how it configures the Application Gateway:
kubectl describe ingress my-tbmq-cluster-http-lb -n tbmqkubectl describe svc my-tbmq-cluster-mqtt-lb -n tbmqkubectl logs deployment/ingress-appgw-deployment -n kube-systemBack up your PostgreSQL database before upgrading. Then review the upgrade instructions for the notes on every version between yours and the target.
Update the chart repository.
helm repo updateCompare versions.
The APP VERSION column is the TBMQ version. Compare your release with the latest chart:
helm list -n tbmqhelm search repo tbmq-helm-chart/tbmq-clusterUpdate values.yaml.
Export the new defaults and compare them with your file:
helm show values tbmq-helm-chart/tbmq-cluster > values-new.yamldiff values.yaml values-new.yamlCarry the changes you need into values.yaml. Always update the image tags, or the release keeps running the old
TBMQ version:
tbmq: image: tag: 2.4.2
tbmq-ie: image: tag: 2.4.2Run the upgrade.
helm upgrade my-tbmq-cluster tbmq-helm-chart/tbmq-cluster -n tbmq \ -f values.yaml \ --set upgrade.upgradeDbSchema=trueA pre-upgrade job migrates the database, then Kubernetes replaces the TBMQ pods one at a time, each after the previous one is ready. Wait for it to finish:
kubectl rollout status statefulset/my-tbmq-cluster-tbmq-node -n tbmq --timeout=600sIf the APP VERSION doesn’t change, there is nothing to migrate: run the same helm upgrade without
--set upgrade.upgradeDbSchema=true. With it, the migration fails with database already upgraded to current version
and the release is marked failed; running the upgrade again without the flag fixes it.
Chart 2.0.0 (TBMQ 2.3.0) removed the PostgreSQL, Kafka, and Redis subcharts that chart 1.x bundled. To upgrade a release from chart 1.x, follow Upgrading from chart version 1.x to 2.0.0 in the chart documentation.
helm uninstall my-tbmq-cluster -n tbmqThis removes the TBMQ resources of the release, and AKS deletes the Azure Load Balancer rules and the Application Gateway configuration for them. It keeps the broker’s data volumes; delete them with:
kubectl delete pvc -n tbmq -l app=my-tbmq-cluster-tbmq-nodePostgreSQL, Kafka, and Valkey keep running, and so do the Secrets you created.
To remove the in-cluster dependencies too, delete the database and Kafka clusters while their operators still run, then the operators, Valkey, and the namespace:
kubectl delete postgrescluster tbmq-db -n tbmqkubectl delete kafka tbmq-kafka -n tbmqkubectl delete kafkanodepool combined -n tbmqhelm uninstall valkey strimzi pgo -n tbmqkubectl delete namespace tbmqDeleting the namespace first leaves it stuck in Terminating: the operators are removed before they can clean up their
clusters. Deleting the namespace also deletes the remaining volumes and their disks.
If you use Azure managed services, only Kafka runs in the cluster. Delete it, then its operator and the namespace:
kubectl delete kafka tbmq-kafka -n tbmqkubectl delete kafkanodepool combined -n tbmqhelm uninstall strimzi -n tbmqkubectl delete namespace tbmqThe managed services aren’t affected; Delete the AKS cluster covers them.
Delete the resource group. This deletes everything in it: the AKS cluster with its node resource group and Application Gateway, the virtual network, and the managed services and their private endpoint and DNS zones, if you created them. It takes about 15 minutes:
az group delete --name $AKS_RESOURCE_GROUPSet up client credentials, then publish and subscribe with an MQTT client. See Getting started.
Choose the authentication provider that fits your clients. See Security overview.
Change broker settings through environment variables in tbmq.customEnv of your values.yaml.
See How to change configuration.
Track sessions, throughput, and resource usage as traffic grows. See Monitoring.
Was this helpful?