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 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
Azure managed services
Load balancer ports
Install the following tools:
az)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.
git clone -b release-2.4.2 https://github.com/thingsboard/tbmq-pe-k8s.gitcd tbmq-pe-k8s/azureRun every command in this guide from this directory.
Sign in and select the subscription to deploy into:
az loginRegister the resource providers this guide uses. A provider registers once per subscription; the command returns at once for those that already are:
for ns in Microsoft.ContainerService Microsoft.Network Microsoft.DBforPostgreSQL Microsoft.Cache; 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. 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:
az group create --name $AKS_RESOURCE_GROUP --location $AKS_LOCATIONCreate 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:
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/24The 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:
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. --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:
az aks get-credentials --resource-group $AKS_RESOURCE_GROUP --name $TB_CLUSTER_NAMEkubectl get nodesCreate 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:
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 falseCreate 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:
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' \ --yesThe server takes about 10 minutes to create. Recommendations:
--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.Standard_D2ds_v5); see
Compute options.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:
az postgres flexible-server db create --resource-group $AKS_RESOURCE_GROUP \ --server-name $TB_DATABASE_NAME --name thingsboard_mqtt_brokerTBMQ 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:
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 DisabledThe cache takes about 10 minutes to create. Recommendations:
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.EnterpriseCluster serves every shard through one endpoint, which TBMQ uses as a standalone
connection.10000.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:
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 redisGet the host name of the server:
az postgres flexible-server show --resource-group $AKS_RESOURCE_GROUP --name $TB_DATABASE_NAME \ --query fullyQualifiedDomainName -o tsvIn 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:
az 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 tsvIn 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:
./k8s-install-tbmq.shWhen it finishes, the output includes:
INFO o.t.m.b.i.ThingsboardMqttBrokerInstallService - Installation finished successfully!Create a Kubernetes Secret with your license key:
export TBMQ_LICENSE_KEY=YOUR_LICENSE_KEY_HEREkubectl create -n thingsboard-mqtt-broker secret generic tbmq-license --from-literal=license-key=$TBMQ_LICENSE_KEYKafka 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.
kubectl apply -f kafka/tbmq-kafka.ymlkubectl rollout status statefulset/tbmq-kafka --timeout=300sUncomment 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.
helm install tbmq-kafka -f kafka/operator/values-strimzi-kafka-operator.yaml oci://quay.io/strimzi-helm/strimzi-kafka-operator --version 0.47.0kubectl apply -f kafka/operator/kafka-cluster.yamlkubectl wait kafka/tbmq --for=condition=Ready --timeout=300sUncomment the block marked Uncomment the following lines to connect to Strimzi.
Deploy TBMQ:
./k8s-deploy-tbmq.shWait until the broker nodes are ready:
kubectl rollout status statefulset/tbmq -n thingsboard-mqtt-broker --timeout=600skubectl get pods -n thingsboard-mqtt-brokerNAME READY STATUS RESTARTS AGEtbmq-0 1/1 Running 0 2mtbmq-1 1/1 Running 0 2mtbmq-integration-executor-0 1/1 Running 0 2mtbmq-integration-executor-1 1/1 Running 0 2mtbmq-kafka-0 1/1 Running 0 5mtbmq-kafka-1 1/1 Running 0 5mtbmq-kafka-2 1/1 Running 0 5mThe 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 |
kubectl apply -f receipts/http-load-balancer.ymlThe 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:
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_PASSWORDBoth manifests configure the same Application Gateway, so apply only one. If you applied the HTTP manifest, delete it, then apply the HTTPS one:
kubectl delete -f receipts/http-load-balancer.yml --ignore-not-foundkubectl apply -f receipts/https-load-balancer.ymlPoint your domain at the gateway’s address, shown in Validate HTTP access, with a DNS A
record.
kubectl apply -f receipts/mqtt-load-balancer.ymlThe 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:
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:
kubectl apply -f tbmq.ymlGet the address of the Application Gateway:
kubectl get ingress -n thingsboard-mqtt-brokerNAME CLASS HOSTS ADDRESS PORTS AGEtbmq-http-loadbalancer azure-application-gateway * 20.56.253.254 80 2mOpen http://{ADDRESS} in your browser, or your domain over HTTPS if you deployed the HTTPS load balancer, 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 tbmq-mqtt-loadbalancer -n thingsboard-mqtt-brokerNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEtbmq-mqtt-loadbalancer LoadBalancer 10.0.183.214 20.76.143.18 1883:31215/TCP,8084:30447/TCP,8883:32014/TCP,8085:31871/TCP 2mMQTT 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:
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.
View the logs of a broker node:
kubectl logs -f tbmq-0 -n thingsboard-mqtt-brokerCheck the state of the StatefulSets:
kubectl get statefulsets -n thingsboard-mqtt-brokerIf 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:
kubectl describe ingress -n thingsboard-mqtt-brokerkubectl describe svc tbmq-mqtt-loadbalancer -n thingsboard-mqtt-brokerkubectl logs deployment/ingress-appgw-deployment -n kube-systemSee the kubectl Cheat Sheet for more details.
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.
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.
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.
No third-party component changes are required — the official images are already in use since v2.2.0.
Proceed with the upgrade.
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:
./k8s-delete-tbmq.sh./k8s-upgrade-tbmq.sh --fromVersion=ce./k8s-deploy-tbmq.shThe upgrade merges the new release branch into your clone and keeps your settings. Git merges only committed changes, so commit your settings first:
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:
git pull --no-rebase --no-edit origin release-2.4.2If the merge reports conflicts, list the conflicting files:
git diff --name-only --diff-filter=UIf 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:
git merge --abortgit 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:
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:
./k8s-upgrade-tbmq.sh./k8s-deploy-tbmq.shTo 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.
Delete the TBMQ nodes.
./k8s-delete-tbmq.shDelete Kafka, if it runs with Strimzi. Delete the Kafka cluster first, then the operator:
kubectl delete -f kafka/operator/kafka-cluster.yamlhelm uninstall tbmq-kafkaDelete 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:
./k8s-delete-all.shDelete 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:
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.yml.
See How to change configuration.
Track sessions, throughput, and resource usage as traffic grows. See Monitoring.
Was this helpful?