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 Amazon Elastic Kubernetes Service (EKS) with the TBMQ Kubernetes scripts.
The scripts deploy two TBMQ broker nodes and two Integration Executors. TBMQ stores its data in Amazon RDS for PostgreSQL, Amazon MSK (Kafka), and Amazon ElastiCache (Valkey), which you create in the AWS Console. Web traffic goes through an AWS Application Load Balancer (ALB) and MQTT traffic through an AWS Network Load Balancer (NLB).
EKS cluster
AWS managed services
Load balancer ports
Install the following tools:
Your AWS credentials need permission to create EKS clusters, VPCs, EC2 instances, IAM roles, load balancers, and RDS, MSK, and ElastiCache resources.
git clone -b release-2.4.2 https://github.com/thingsboard/tbmq.gitcd tbmq/k8s/awsRun every command in this guide from this directory.
Set your access key, secret key, and default region:
aws configureTo create access keys, see Manage access keys for IAM users.
Review these fields in cluster.yml:
region and availabilityZones: the AWS region and three of its availability zones. The defaults are us-east-1
and us-east-1a, us-east-1b, us-east-1c.version: the Kubernetes version. List the versions EKS offers in your region with
aws eks describe-cluster-versions --region {region} --query 'clusterVersions[].clusterVersion'.instanceType: the EC2 instance type of each node group, m7a.large by default. Not every type is offered in every
region; see Check instance types in your region.desiredCapacity: the number of nodes in each node group, 2 by default.To size the instances for production, see Amazon EC2 instance types.
Check that the region offers the instance type in your cluster.yml:
aws ec2 describe-instance-type-offerings --region us-east-1 --location-type availability-zone \ --filters Name=instance-type,Values=m7a.large \ --query 'InstanceTypeOfferings[].[InstanceType,Location]' --output textThe type must be listed for every zone in availabilityZones. If it isn’t, pick another type, such as m7i.large.
cluster.yml creates two node groups in private subnets. Each node carries a role label, which pins the workload
to it:
| Node group | role label |
Runs |
|---|---|---|
managed |
tbmq |
TBMQ broker |
tbmq-ie |
tbmq-ie |
TBMQ Integration Executor |
The broker and the Integration Executor each run two replicas on separate nodes, so each group needs at least two
nodes. To run both on the same nodes, give the nodes both labels or change nodeSelector in tbmq-ie.yml.
The iam block enables
IAM roles for service accounts
and creates the aws-load-balancer-controller service account with the IAM policy the
AWS Load Balancer Controller
needs:
iam: withOIDC: true serviceAccounts: - metadata: name: aws-load-balancer-controller namespace: kube-system wellKnownPolicies: awsLoadBalancerController: trueThe addons block installs these EKS add-ons:
aws-ebs-csi-driver: provisions EBS volumes for persistent volume claims.vpc-cni: gives each pod an IP address in the VPC.coredns: cluster DNS.kube-proxy: routes Service traffic on each node.eksctl create cluster -f cluster.ymlThis takes about 20 minutes. When it finishes, eksctl adds the cluster to your kubeconfig and switches the current
context to it.
The controller creates the ALB and the NLB for TBMQ. eksctl already created its service account and IAM role, so
install it with that service account:
helm repo add eks https://aws.github.io/eks-chartshelm repo updatehelm install aws-load-balancer-controller eks/aws-load-balancer-controller \ -n kube-system \ --set clusterName=tbmq \ --set serviceAccount.create=false \ --set serviceAccount.name=aws-load-balancer-controllerkubectl rollout status deployment/aws-load-balancer-controller -n kube-system --timeout=180sCreate the PostgreSQL database, the Kafka cluster, and the Valkey cache in the VPC that eksctl created for the
cluster, in its private subnets, and attach the eksctl-tbmq-cluster-ClusterSharedNodeSecurityGroup-* security
group to each. That security group allows traffic from the cluster nodes, so TBMQ can reach the services without
further rules. To find the VPC, the private subnets, and the security group:
aws cloudformation describe-stacks --region us-east-1 --stack-name eksctl-tbmq-cluster \ --query "Stacks[0].Outputs[?OutputKey=='VPC' || OutputKey=='SubnetsPrivate' || OutputKey=='SharedNodeSecurityGroup'].[OutputKey,OutputValue]" \ --output textIn the AWS Console, the VPC is named eksctl-tbmq-cluster/VPC. Create the three services in the cluster’s region. You
can create them in parallel; Amazon MSK takes the longest, about 30 minutes.
Create a PostgreSQL database on Amazon RDS. To get started, follow the official AWS RDS setup guide.
Recommendations:
username and set a secure password. You need both to configure TBMQ.db.m7g.large. Right-size first, optimize later.eksctl-tbmq-cluster-ClusterSharedNodeSecurityGroup-* security group.thingsboard_mqtt_broker under Additional configuration. TBMQ connects to this
database; RDS doesn’t create it unless you set the name.Create an Amazon MSK cluster. Open the AWS Console → MSK → Create cluster → Custom create.
Recommendations:
kafka.m7g.large brokers. Scale up later if needed.eksctl-tbmq-cluster-ClusterSharedNodeSecurityGroup-* security group.TBMQ uses Valkey 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.
Open the AWS Console → ElastiCache → Valkey caches → Create cache.
Recommendations:
cache.r7g.large; at least 1 GB RAM for dev/test.eksctl-tbmq-cluster-ClusterSharedNodeSecurityGroup-* security group.REDIS_PASSWORD.Once the database is Available, get its endpoint. {db-identifier} is the DB identifier you set when you created
it:
aws rds describe-db-instances --region us-east-1 --db-instance-identifier {db-identifier} \ --query 'DBInstances[0].Endpoint.Address' --output textIn tbmq-db-configmap.yml, replace RDS_URL_HERE in SPRING_DATASOURCE_URL with the endpoint, and set the
username and password you chose:
SPRING_DATASOURCE_URL: "jdbc:postgresql://my-tbmq-db.xxxxxx.us-east-1.rds.amazonaws.com:5432/thingsboard_mqtt_broker" SPRING_DATASOURCE_USERNAME: "YOUR_RDS_POSTGRES_USER" SPRING_DATASOURCE_PASSWORD: "YOUR_RDS_POSTGRES_PASSWORD"Once the MSK cluster is Active, get its bootstrap servers. {cluster-arn} is the cluster’s ARN, shown on its
details page:
aws kafka get-bootstrap-brokers --region us-east-1 --cluster-arn {cluster-arn}Copy the BootstrapBrokerString value, the plaintext brokers on port 9092. In both tbmq.yml and tbmq-ie.yml,
replace PUT_YOUR_KAFKA_SERVERS_HERE with it:
- name: TB_KAFKA_SERVERS value: "b-1.my-msk.xxxxxx.c2.kafka.us-east-1.amazonaws.com:9092,b-2.my-msk.xxxxxx.c2.kafka.us-east-1.amazonaws.com:9092"To connect over TLS instead, copy BootstrapBrokerStringTls, the brokers on port 9094, and add this variable next to
TB_KAFKA_SERVERS in both files:
- name: TB_KAFKA_DEFAULT_PRODUCER_CONSUMER_CONFIG value: "security.protocol:SSL"Once the cache is Available, get its endpoint. {cache-name} is the name you gave the cache:
aws elasticache describe-replication-groups --region us-east-1 --replication-group-id {cache-name} \ --query 'ReplicationGroups[0].[ConfigurationEndpoint.Address,NodeGroups[0].PrimaryEndpoint.Address]' --output textWith cluster mode enabled, the command prints the configuration endpoint; with cluster mode disabled, it prints None
and the primary endpoint.
Set the endpoint in tbmq-cache-configmap.yml. With cluster mode enabled, set the configuration endpoint with port
6379 in REDIS_NODES:
REDIS_CONNECTION_TYPE: "cluster" REDIS_NODES: "clustercfg.my-cache.xxxxxx.use1.cache.amazonaws.com:6379"With cluster mode disabled, set the primary endpoint, without the port, in REDIS_HOST:
REDIS_CONNECTION_TYPE: "standalone" REDIS_HOST: "master.my-cache.xxxxxx.use1.cache.amazonaws.com"If you enabled encryption in transit, also add:
REDIS_SSL_ENABLED: "true" REDIS_SSL_CERT_FILE: "/etc/ssl/certs/ca-certificates.crt"ElastiCache certificates are issued by Amazon’s root CAs, which the CA bundle in the TBMQ image already contains. If
you set a password, uncomment REDIS_PASSWORD and set it.
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!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 2mThe receipts directory holds one manifest per load balancer. The AWS Load Balancer Controller creates an
internet-facing load balancer for each one you apply:
| Manifest | Load balancer | Ports |
|---|---|---|
http-load-balancer.yml |
ALB | 80 (HTTP) |
https-load-balancer.yml |
ALB | 443 (HTTPS); 80 redirects to HTTPS |
mqtt-load-balancer.yml |
NLB | 1883 (MQTT), 8084 (MQTT over WebSockets); 8883 and 8085 passed through to TBMQ |
mqtts-load-balancer.yml |
NLB | 1883, 8084; 8883 (MQTTS) and 8085 (MQTT over secure WebSockets) with TLS termination |
Apply one ALB manifest and one NLB manifest. The HTTPS and one-way TLS manifests set the
ELBSecurityPolicy-TLS13-1-2-2021-06 security policy, which allows TLS 1.3 and 1.2.
kubectl apply -f receipts/http-load-balancer.ymlThe ALB serves HTTPS with a certificate from
AWS Certificate Manager (ACM).
Request or import a certificate for your domain in the cluster’s region and note its ARN. In
receipts/https-load-balancer.yml, replace YOUR_HTTPS_CERTIFICATE_ARN with it, then apply the manifest:
kubectl apply -f receipts/https-load-balancer.ymlAfter the ALB is created, point your domain at its address with a DNS CNAME record.
kubectl apply -f receipts/mqtt-load-balancer.ymlThis NLB serves plain MQTT. It also forwards ports 8883 and 8085 to TBMQ unchanged, which serves them only with
two-way TLS.
The NLB decrypts MQTTS and secure WebSockets traffic with an ACM certificate and forwards it to TBMQ’s plain ports:
8883 to 1883 and 8085 to 8084. Traffic between the NLB and TBMQ stays inside your VPC, unencrypted.
Request or import a certificate in ACM and note its ARN. In receipts/mqtts-load-balancer.yml, replace
YOUR_MQTTS_CERTIFICATE_ARN with it, then apply the manifest instead of mqtt-load-balancer.yml:
kubectl apply -f receipts/mqtts-load-balancer.ymlWith two-way TLS, the NLB forwards ports 8883 and 8085 unchanged, and TBMQ terminates TLS itself. This 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, and the transparent NLB:
kubectl apply -f tbmq.ymlkubectl apply -f receipts/mqtt-load-balancer.ymlGet the address of the ALB:
kubectl get ingress -n thingsboard-mqtt-brokerNAME CLASS HOSTS ADDRESS PORTS AGEtbmq-http-loadbalancer alb * k8s-thingsbo-tbmqhttp-000aba1305-222186756.us-east-1.elb.amazonaws.com 80 3mThe ALB takes a few minutes to provision. Then open 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 NLB:
kubectl get svc -n thingsboard-mqtt-brokerNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEtbmq ClusterIP 10.100.42.17 <none> 8083/TCP,1883/TCP,8883/TCP,8084/TCP,8085/TCP 10mtbmq-integration-executor ClusterIP 10.100.12.121 <none> 8082/TCP 10mtbmq-mqtt-loadbalancer LoadBalancer 10.100.119.170 k8s-thingsbo-tbmqmqtt-b9f99d1ab6-1049a98ba4e28403.elb.us-east-1.amazonaws.com 1883:30308/TCP,8084:31760/TCP,8883:31609/TCP,8085:30172/TCP 3mMQTT clients connect to the EXTERNAL-IP of tbmq-mqtt-loadbalancer, or tbmq-mqtts-loadbalancer for one-way TLS, on
the ports listed in Configure load balancers. The NLB address resolves a few minutes after
it is created.
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 eks' -q 1The subscriber prints tbmq/demo/hello hello from eks. 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, Kafka, or Valkey, check the endpoint you set and that the service
has the eksctl-tbmq-cluster-ClusterSharedNodeSecurityGroup-* security group attached.
If the Ingress ADDRESS or the Service EXTERNAL-IP stays empty, the AWS Load Balancer Controller couldn’t create the
load balancer. Its events and logs give the reason:
kubectl describe ingress -n thingsboard-mqtt-brokerkubectl describe svc tbmq-mqtt-loadbalancer -n thingsboard-mqtt-brokerkubectl logs deployment/aws-load-balancer-controller -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. Plan the third-party component migration |
| 2.2.0 | Delete the TBMQ pods first. Check the authentication settings in database-setup.yml |
Backing up your PostgreSQL database before upgrading is highly recommended but optional. For guidance, follow the AWS RDS backup and restore instructions.
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.
Then 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.
Then 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.
Then proceed with the upgrade.
Review the third-party component updates for full details.
Then proceed with the upgrade.
The upgrade script reads from database-setup.yml. Variables from tbmq.yml are
not applied during the upgrade — only the values in
database-setup.yml are used. Ensure this file reflects your active configuration.
Supported variables in database-setup.yml
SECURITY_MQTT_BASIC_ENABLED (true|false)SECURITY_MQTT_SSL_ENABLED (true|false)SECURITY_MQTT_SSL_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT (true|false) — usually falseOnce the file is verified, proceed with the upgrade.
The 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.shDelete the TBMQ nodes.
./k8s-delete-tbmq.shDelete every resource in the thingsboard-mqtt-broker namespace, including the load balancer Ingress and Services:
./k8s-delete-all.shWait for the load balancers to go. The AWS Load Balancer Controller then deletes the ALB and the NLB. Wait until
this command lists no load balancer whose name starts with k8s-thingsbo:
aws elbv2 describe-load-balancers --region us-east-1 --query 'LoadBalancers[].LoadBalancerName'Delete the managed services. Delete the Amazon RDS database, the Amazon MSK cluster, and the Amazon ElastiCache
cache in the AWS Console, and wait until they are deleted. They use the cluster’s VPC and security group, so eksctl
can’t delete the cluster while they exist. Then delete the subnet groups created for them: the DB subnet group in
RDS → Subnet groups and the cache subnet group in ElastiCache → Subnet groups. Deleting the database
and the cache doesn’t remove them.
Delete the controller and the EKS cluster (update the cluster name and region if different):
helm uninstall aws-load-balancer-controller -n kube-systemeksctl delete cluster -r us-east-1 -n tbmq -wSet 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?