Skip to content
Stand with Ukraine flag

Azure

This guide covers deploying a TBMQ cluster on Azure Kubernetes Service (AKS) with the TBMQ Kubernetes scripts.

The scripts deploy two TBMQ broker nodes and two Integration Executors. TBMQ stores its data in Azure Database for PostgreSQL and Azure Managed Redis, which you create with the az CLI, and in a Kafka cluster that runs in AKS. Web traffic goes through an Azure Application Gateway, which the AKS ingress add-on configures from a Kubernetes Ingress, and MQTT traffic through an Azure Load Balancer, created from a Kubernetes Service.

AKS cluster

  • TBMQ × 2
  • Integration Executor × 2
  • Kafka × 3

Azure managed services

  • Azure Database for PostgreSQL
  • Azure Managed Redis

Load balancer ports

  • 80 HTTP · Application Gateway TBMQ UI and REST API
  • 443 HTTPS · Application Gateway TBMQ UI and REST API, with the HTTPS load balancer
  • 1883 MQTT · Azure LB MQTT clients
  • 8084 MQTT over WebSockets · Azure LB MQTT clients that connect over WebSockets
  • 8883 MQTTS · Azure LB MQTT clients that connect over TLS, once you enable MQTTS in TBMQ
  • 8085 MQTT over secure WebSockets · Azure LB MQTT clients that connect over secure WebSockets, once you enable MQTTS in TBMQ

Install the following tools:

Your Azure account needs permission to create resource groups, virtual networks, AKS clusters, Azure Database for PostgreSQL servers, Azure Managed Redis caches, private endpoints, and private DNS zones, and to assign roles on the virtual network, for example the Owner role on the subscription.

You need a TBMQ PE license key. To buy one, open the Pricing page, choose a pay-as-you-go subscription or a perpetual license, and use the calculator to size your deployment: session and throughput limits, production and development instances, and any add-ons.

You apply the key in Configure the license key.

Clone TBMQ K8S repository

Section titled Clone TBMQ K8S repository
Terminal window
git clone -b release-2.4.2 https://github.com/thingsboard/tbmq-pe-k8s.git
cd tbmq-pe-k8s/azure

Run every command in this guide from this directory.

Sign in and select the subscription to deploy into:

Terminal window
az login

Register the resource providers this guide uses. A provider registers once per subscription; the command returns at once for those that already are:

Terminal window
for ns in Microsoft.ContainerService Microsoft.Network Microsoft.DBforPostgreSQL Microsoft.Cache; do
az provider register --namespace $ns --wait
done

The 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:

Terminal window
export AKS_RESOURCE_GROUP=TBMQResources
export AKS_LOCATION=eastus
export AKS_GATEWAY=tbmq-gateway
export TB_CLUSTER_NAME=tbmq-cluster
export TB_DATABASE_NAME=tbmq-db
export TB_REDIS_NAME=tbmq-cache
echo "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. Each is part of a public DNS name, so it must be unique across Azure: if a create command reports the name as taken, choose another, for example by adding your company name.

Create the resource group:

Terminal window
az group create --name $AKS_RESOURCE_GROUP --location $AKS_LOCATION

Create a virtual network with a subnet for each part of the deployment: the AKS nodes and pods, the PostgreSQL server, and the private endpoint of the Redis cache. The ingress add-on adds a fourth subnet, 10.10.16.0/24, for the Application Gateway when it creates the cluster:

Terminal window
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/24

The PostgreSQL server and the Redis cache get private IP addresses in this network only, so they aren’t reachable from the internet.

Create a cluster with three Standard_D4s_v6 nodes, one in each availability zone of the region, and the Application Gateway ingress add-on:

Terminal window
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 3

This takes about 10 minutes. --network-plugin azure gives each pod an IP address in the aks subnet, which the Application Gateway routes to directly. 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:

Terminal window
az aks get-credentials --resource-group $AKS_RESOURCE_GROUP --name $TB_CLUSTER_NAME
kubectl get nodes

Create the PostgreSQL server and the Redis cache in the virtual network. You can create them while the AKS cluster is being created.

The server resolves its name within the virtual network through a private DNS zone. Create the zone and link it to the network:

Terminal window
az network private-dns zone create --resource-group $AKS_RESOURCE_GROUP \
--name tbmq.private.postgres.database.azure.com
az network private-dns link vnet create --resource-group $AKS_RESOURCE_GROUP \
--zone-name tbmq.private.postgres.database.azure.com --name tbmq-postgres-dns-link \
--virtual-network tbmq-vnet --registration-enabled false

Create a PostgreSQL 17 flexible server in the postgres subnet, highly available with a standby server in another availability zone. Replace YOUR_DB_PASSWORD with a strong password of 8 to 128 characters that mixes upper and lower case letters, digits, and symbols other than quotes and backslashes; you need it to connect TBMQ:

Terminal window
az postgres flexible-server create --resource-group $AKS_RESOURCE_GROUP \
--name $TB_DATABASE_NAME \
--location $AKS_LOCATION \
--version 17 \
--tier GeneralPurpose --sku-name Standard_D2ds_v5 \
--storage-size 32 \
--zonal-resiliency Enabled \
--vnet tbmq-vnet --subnet postgres \
--private-dns-zone tbmq.private.postgres.database.azure.com \
--admin-user tbmqadmin --admin-password 'YOUR_DB_PASSWORD' \
--yes

The server takes about 10 minutes to create. Recommendations:

  • High availability: --zonal-resiliency Enabled keeps a standby server in another zone. If the command fails with This location has a single availability zone, the region doesn’t offer zone-redundant high availability to your subscription: add --allow-same-zone to keep the standby in the same zone. For development, --zonal-resiliency Disabled runs a single server at half the cost.
  • Size: give production at least 2 vCores (Standard_D2ds_v5); see Compute options.
  • Network: the server gets an address in the postgres subnet only. If the command fails with PrivateDnsZoneNameNotValid, the private DNS zone doesn’t exist yet: create it as shown above.

Create the database TBMQ connects to:

Terminal window
az postgres flexible-server db create --resource-group $AKS_RESOURCE_GROUP \
--server-name $TB_DATABASE_NAME --name thingsboard_mqtt_broker

TBMQ uses a Redis-compatible cache to store messages for DEVICE persistent clients and to cache MQTT client credentials. Without the cache, every new connection queries the database to validate its credentials, which can overload the database under high connection rates.

Azure Managed Redis runs Redis 7.4, compatible with the Valkey 8 that TBMQ supports. Create a cache with access-key authentication and no public network access:

Terminal window
az redisenterprise create --resource-group $AKS_RESOURCE_GROUP \
--name $TB_REDIS_NAME \
--location $AKS_LOCATION \
--sku Balanced_B1 \
--clustering-policy EnterpriseCluster \
--client-protocol Encrypted \
--access-keys-authentication Enabled \
--public-network-access Disabled

The cache takes about 10 minutes to create. Recommendations:

  • Size: Balanced_B1 (1 GB) to start. DEVICE persistent clients keep their undelivered messages in the cache, so size it for them; see Choosing the right tier.
  • Clustering policy: EnterpriseCluster serves every shard through one endpoint, which TBMQ uses as a standalone connection.
  • TLS: clients connect over TLS on port 10000.
  • High availability: on by default, with a replica of each shard.

The cache reaches the virtual network through a private endpoint in the endpoints subnet. Create the endpoint and a private DNS zone that resolves the cache’s name to it:

Terminal window
az network private-dns zone create --resource-group $AKS_RESOURCE_GROUP \
--name privatelink.redis.azure.net
az network private-dns link vnet create --resource-group $AKS_RESOURCE_GROUP \
--zone-name privatelink.redis.azure.net --name tbmq-redis-dns-link \
--virtual-network tbmq-vnet --registration-enabled false
az network private-endpoint create --resource-group $AKS_RESOURCE_GROUP \
--name tbmq-redis-endpoint \
--vnet-name tbmq-vnet --subnet endpoints \
--private-connection-resource-id $(az redisenterprise show --resource-group $AKS_RESOURCE_GROUP \
--name $TB_REDIS_NAME --query id -o tsv) \
--group-id redisEnterprise \
--connection-name tbmq-redis-connection
az network private-endpoint dns-zone-group create --resource-group $AKS_RESOURCE_GROUP \
--endpoint-name tbmq-redis-endpoint --name default \
--private-dns-zone privatelink.redis.azure.net --zone-name redis

Get the host name of the server:

Terminal window
az postgres flexible-server show --resource-group $AKS_RESOURCE_GROUP --name $TB_DATABASE_NAME \
--query fullyQualifiedDomainName -o tsv

In tbmq-db-configmap.yml, replace YOUR_AZURE_POSTGRES_ENDPOINT_URL with it, YOUR_AZURE_POSTGRES_USER with tbmqadmin, and YOUR_AZURE_POSTGRES_PASSWORD with the password you set:

SPRING_DATASOURCE_URL: "jdbc:postgresql://tbmq-db.postgres.database.azure.com/thingsboard_mqtt_broker?sslmode=require"
SPRING_DATASOURCE_USERNAME: "tbmqadmin"
SPRING_DATASOURCE_PASSWORD: "secret"

Once the cache is Running, get its host name and access key:

Terminal window
az redisenterprise show --resource-group $AKS_RESOURCE_GROUP --name $TB_REDIS_NAME \
--query hostName -o tsv
az redisenterprise database list-keys --resource-group $AKS_RESOURCE_GROUP \
--cluster-name $TB_REDIS_NAME --query primaryKey -o tsv

In tbmq-cache-configmap.yml, replace YOUR_REDIS_HOST_NAME with the host name and YOUR_REDIS_ACCESS_KEY with the key:

REDIS_CONNECTION_TYPE: "standalone"
REDIS_HOST: "tbmq-cache.eastus.redis.azure.net"
REDIS_PORT: "10000"
REDIS_PASSWORD: "YOUR_REDIS_ACCESS_KEY"
REDIS_SSL_ENABLED: "true"
REDIS_SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt"

TBMQ verifies the cache’s TLS certificate against the CA certificates of its container image, which include the roots that Azure certificates chain to.

Run the installation script. It creates the thingsboard-mqtt-broker namespace, sets it as the namespace of your current kubectl context, and creates the TBMQ database schema:

Terminal window
./k8s-install-tbmq.sh

When it finishes, the output includes:

INFO o.t.m.b.i.ThingsboardMqttBrokerInstallService - Installation finished successfully!

Configure the license key

Section titled Configure the license key

Create a Kubernetes Secret with your license key:

Terminal window
export TBMQ_LICENSE_KEY=YOUR_LICENSE_KEY_HERE
kubectl create -n thingsboard-mqtt-broker secret generic tbmq-license --from-literal=license-key=$TBMQ_LICENSE_KEY

Kafka runs in the AKS cluster. Deploy it with one of these options, and in both tbmq.yml and tbmq-ie.yml uncomment the matching TB_KAFKA_SERVERS block.

Three pods in KRaft dual-role mode: each node is both a controller and a broker. See the full deployment guide.

Terminal window
kubectl apply -f kafka/tbmq-kafka.yml
kubectl rollout status statefulset/tbmq-kafka --timeout=300s

Uncomment the block marked Uncomment the following lines to connect to Apache Kafka.

The Strimzi Cluster Operator manages upgrades and scaling. See the full deployment guide.

Terminal window
helm install tbmq-kafka -f kafka/operator/values-strimzi-kafka-operator.yaml oci://quay.io/strimzi-helm/strimzi-kafka-operator --version 0.47.0
kubectl apply -f kafka/operator/kafka-cluster.yaml
kubectl wait kafka/tbmq --for=condition=Ready --timeout=300s

Uncomment the block marked Uncomment the following lines to connect to Strimzi.

Deploy TBMQ:

Terminal window
./k8s-deploy-tbmq.sh

Wait until the broker nodes are ready:

Terminal window
kubectl rollout status statefulset/tbmq -n thingsboard-mqtt-broker --timeout=600s
kubectl get pods -n thingsboard-mqtt-broker
NAME READY STATUS RESTARTS AGE
tbmq-0 1/1 Running 0 2m
tbmq-1 1/1 Running 0 2m
tbmq-integration-executor-0 1/1 Running 0 2m
tbmq-integration-executor-1 1/1 Running 0 2m
tbmq-kafka-0 1/1 Running 0 5m
tbmq-kafka-1 1/1 Running 0 5m
tbmq-kafka-2 1/1 Running 0 5m

The receipts directory holds one manifest per load balancer. Apply one HTTP manifest and the MQTT manifest:

Manifest Load balancer Ports
http-load-balancer.yml Application Gateway 80 (HTTP)
https-load-balancer.yml Application Gateway 443 (HTTPS); 80 redirects to HTTPS
mqtt-load-balancer.yml Azure Load Balancer 1883 (MQTT), 8084 (MQTT over WebSockets); 8883 and 8085 passed through to TBMQ
Terminal window
kubectl apply -f receipts/http-load-balancer.yml

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 as TBMQHTTPSCert, the name the manifest refers to. The ingress add-on creates the gateway in the cluster’s node resource group:

Terminal window
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_PASSWORD

Both manifests configure the same Application Gateway, so apply only one. If you applied the HTTP manifest, delete it, then apply the HTTPS one:

Terminal window
kubectl delete -f receipts/http-load-balancer.yml --ignore-not-found
kubectl apply -f receipts/https-load-balancer.yml

Point your domain at the gateway’s address, shown in Validate HTTP access, with a DNS A record.

Terminal window
kubectl apply -f receipts/mqtt-load-balancer.yml

The Azure Load Balancer passes TCP through to TBMQ unchanged, so it can’t terminate TLS. It serves plain MQTT on 1883 and 8084, and forwards 8883 and 8085 to TBMQ, which serves them once you enable MQTT over TLS.

TBMQ terminates TLS itself on 8883 (MQTTS) and 8085 (MQTT over secure WebSockets). This also supports X.509 certificate authentication.

Prepare the server certificate chain and its private key in PEM format; see MQTT over SSL. Create a ConfigMap from them. The same command replaces the files when you renew the certificate:

Terminal window
kubectl create configmap tbmq-mqtts-config -n thingsboard-mqtt-broker \
--from-file=server.pem=YOUR_PEM_FILENAME \
--from-file=mqttserver_key.pem=YOUR_PEM_KEY_FILENAME \
-o yaml --dry-run=client | kubectl apply -f -

Where:

  • YOUR_PEM_FILENAME: the server certificate chain file.
  • YOUR_PEM_KEY_FILENAME: the server certificate’s private key file.

In tbmq.yml, uncomment the three blocks marked Uncomment the following lines to enable two-way MQTTS. They mount the certificate and enable MQTTS on 8883 and MQTT over secure WebSockets on 8085. Apply the updated tbmq.yml, which restarts the broker nodes one at a time:

Terminal window
kubectl apply -f tbmq.yml

Get the address of the Application Gateway:

Terminal window
kubectl get ingress -n thingsboard-mqtt-broker
NAME CLASS HOSTS ADDRESS PORTS AGE
tbmq-http-loadbalancer azure-application-gateway * 20.56.253.254 80 2m

Open http://{ADDRESS} in your browser, or your domain over HTTPS if you deployed the HTTPS load balancer, and sign in as System Administrator:

Username
sysadmin@thingsboard.org
Password
sysadmin

Change the password after the first sign-in.

Get the address of the Azure Load Balancer:

Terminal window
kubectl get svc tbmq-mqtt-loadbalancer -n thingsboard-mqtt-broker
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
tbmq-mqtt-loadbalancer LoadBalancer 10.0.183.214 20.76.143.18 1883:31215/TCP,8084:30447/TCP,8883:32014/TCP,8085:31871/TCP 2m

MQTT clients connect to the EXTERNAL-IP on the ports listed in Configure load balancers.

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:

Terminal window
mosquitto_sub -h {EXTERNAL-IP} -p 1883 -u tbmq_websockets_username -t 'tbmq/demo/#' -v -q 1

In another, publish:

Terminal window
mosquitto_pub -h {EXTERNAL-IP} -p 1883 -u tbmq_websockets_username -t 'tbmq/demo/hello' -m 'hello from aks' -q 1

The 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.

View the logs of a broker node:

Terminal window
kubectl logs -f tbmq-0 -n thingsboard-mqtt-broker

Check the state of the StatefulSets:

Terminal window
kubectl get statefulsets -n thingsboard-mqtt-broker

If a broker node logs connection errors to PostgreSQL or Redis, check the host name you set, and that the server’s private DNS zone and the privatelink.redis.azure.net zone are linked to tbmq-vnet. Redis authentication errors mean the access key in tbmq-cache-configmap.yml is wrong.

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:

Terminal window
kubectl describe ingress -n thingsboard-mqtt-broker
kubectl describe svc tbmq-mqtt-loadbalancer -n thingsboard-mqtt-broker
kubectl logs deployment/ingress-appgw-deployment -n kube-system

See the kubectl Cheat Sheet for more details.

  1. Check the version-specific notes below for any preparation your target version requires.
  2. Back up your database (optional but recommended).
  3. Run the upgrade commands.

For full version history and supported upgrade paths, see the upgrade instructions page. If the documentation does not cover your specific upgrade path, contact us for guidance.

What each upgrade needs before you run the upgrade — select a version for its full notes:

Upgrade to Before running the upgrade
2.4.2 Nothing. Check SCRAM-only authentication and Kafka integrations
2.4.1 Nothing. If you set MQTT_TOPIC_MAX_SEGMENTS_COUNT, raise it by 1
2.4.0 Nothing. If you scrape metrics, update queries for the renamed Prometheus metrics
2.3.0 Delete the TBMQ pods first
TBMQ to TBMQ PE Move to the PE repository and set the license key; this path has its own commands

Backing up your PostgreSQL database before upgrading is highly recommended but optional. For guidance, follow the Azure Database for PostgreSQL backup and restore documentation.

This is a standard upgrade from v2.4.1. No third-party component changes are required, and the upgrade only records the new schema version — no table is created or altered and no data is migrated.

Proceed with the upgrade.

This is a standard upgrade from v2.4.0.

No third-party component changes are required, and the upgrade only records the new schema version — no table is created or altered and no data is migrated.

Proceed with the upgrade.

This is a standard upgrade from v2.3.0.

No third-party component changes are required. The upgrade creates the dropped_msg table used by dropped message analytics; no existing table is altered and no data is migrated.

Proceed with the upgrade.

This is a standard upgrade from v2.2.0.

No third-party component changes are required — the official images are already in use since v2.2.0.

Proceed with the upgrade.

Upgrade from TBMQ to TBMQ PE

Section titled Upgrade from TBMQ to TBMQ PE

CE-to-PE migration is supported for the same version only. If you are on an earlier CE version, upgrade TBMQ CE to the latest version first. For all supported paths, see the upgrade instructions.

Before upgrading, merge your current configuration with the latest TBMQ PE K8S scripts. Don’t forget to configure the license key.

Run the following commands to stop TBMQ, migrate the database, and redeploy:

Terminal window
./k8s-delete-tbmq.sh
./k8s-upgrade-tbmq.sh --fromVersion=ce
./k8s-deploy-tbmq.sh

The upgrade merges the new release branch into your clone and keeps your settings. Git merges only committed changes, so commit your settings first:

Terminal window
git add -A .
git commit -m "TBMQ configuration"

If Git asks who you are, set git config user.name and git config user.email, then commit again.

Merge the release branch:

Terminal window
git pull --no-rebase --no-edit origin release-2.4.2

If the merge reports conflicts, list the conflicting files:

Terminal window
git diff --name-only --diff-filter=U

If you didn’t change any of them, for example the pom.xml files of the TBMQ source code, take the release’s version of every conflict:

Terminal window
git merge --abort
git pull --no-rebase --no-edit -X theirs origin release-2.4.2

-X theirs keeps your changes wherever they don’t conflict with the release. If a file you changed conflicts, resolve it by hand instead and run git commit.

Check that your settings are the only differences from the release branch:

Terminal window
git diff --stat origin/release-2.4.2 -- .

After pulling, run the database upgrade and then apply the updated manifests to roll out the new version:

Terminal window
./k8s-upgrade-tbmq.sh
./k8s-deploy-tbmq.sh

To remove TBMQ but keep the AKS cluster and the managed services, run the first three steps. To remove everything this guide created, run the last step alone.

  1. Delete the TBMQ nodes.

    Terminal window
    ./k8s-delete-tbmq.sh
  2. Delete Kafka, if it runs with Strimzi. Delete the Kafka cluster first, then the operator:

    Terminal window
    kubectl delete -f kafka/operator/kafka-cluster.yaml
    helm uninstall tbmq-kafka
  3. Delete the remaining resources in the thingsboard-mqtt-broker namespace: the Services, including the MQTT load balancer, the StatefulSets, including the Kafka StatefulSet, the ConfigMaps, the Ingress, and the persistent volume claims:

    Terminal window
    ./k8s-delete-all.sh
  4. Delete the resource group. This deletes everything in it: the AKS cluster with its node resource group and Application Gateway, the PostgreSQL server, the Redis cache, the private endpoint, the private DNS zones, and the virtual network. It takes about 15 minutes:

    Terminal window
    az group delete --name $AKS_RESOURCE_GROUP

Connect your first client

Set up client credentials, then publish and subscribe with an MQTT client. See Getting started.

Secure the broker

Choose the authentication provider that fits your clients. See Security overview.

Watch the broker

Track sessions, throughput, and resource usage as traffic grows. See Monitoring.