AWS EKS Monolith Setup
This guide walks you through deploying ThingsBoard PE in monolith mode on AWS EKS. We use Amazon RDS for managed PostgreSQL.
Prerequisites
Section titled “Prerequisites”Install and configure tools
Section titled “Install and configure tools”Install kubectl, eksctl, and AWS CLI.
Configure your AWS credentials. To get Access and Secret keys, follow this guide. The default region should be the ID of the region where you want to deploy the cluster.
aws configurePull ThingsBoard PE images
Section titled “Pull ThingsBoard PE images”Verify that you can pull the images from Docker Hub:
docker pull thingsboard/tb-pe-node:4.3.1.1PEdocker pull thingsboard/tb-pe-web-report:4.3.1.1PEStep 1. Clone ThingsBoard PE K8S scripts repository
Section titled “Step 1. Clone ThingsBoard PE K8S scripts repository”git clone -b release-4.3 https://github.com/thingsboard/thingsboard-pe-k8s.git --depth 1cd thingsboard-pe-k8s/aws/monolithStep 2. Configure and create EKS cluster
Section titled “Step 2. Configure and create EKS cluster”In the cluster.yml file you can find the suggested cluster configuration. Key fields you can change:
| Field | Default | Description |
|---|---|---|
region | us-east-1 | AWS region for the cluster |
availabilityZones | [us-east-1a, us-east-1b, us-east-1c] | Region availability zones |
instanceType | m5.xlarge | EC2 instance type for nodes |
Create the cluster:
eksctl create cluster -f cluster.ymlStep 3. Create AWS load-balancer controller
Section titled “Step 3. Create AWS load-balancer controller”Once the cluster is ready, create the AWS load-balancer controller by following this guide.
The cluster provisioning scripts create several load balancers:
| Load Balancer | Type | Purpose |
|---|---|---|
tb-http-loadbalancer | ALB | Web UI, REST API, HTTP transport |
tb-mqtt-loadbalancer | NLB | MQTT transport |
tb-coap-loadbalancer | NLB | CoAP transport |
tb-edge-loadbalancer | NLB | Edge instances connectivity |
Step 4. Provision databases
Section titled “Step 4. Provision databases”4.1 Amazon PostgreSQL DB configuration
Section titled “4.1 Amazon PostgreSQL DB configuration”Set up PostgreSQL on Amazon RDS. ThingsBoard uses it as the main database for devices, dashboards, rule chains, and device telemetry. Follow this guide, but take into account the following requirements:
- Keep your PostgreSQL password in a safe place. We will refer to it later as YOUR_RDS_PASSWORD.
- Make sure your PostgreSQL version is latest 16.x.
- Make sure your PostgreSQL RDS instance is accessible from the ThingsBoard cluster. The easiest way is to deploy the RDS instance in the same VPC and use the
eksctl-thingsboard-cluster-ClusterSharedNodeSecurityGroup-*security group. - Make sure you use “thingsboard” as the initial database name. If you do not specify a database name, Amazon RDS does not create one.
Recommendations:
- Use Production template for high availability.
- Use Provisioned IOPS for better performance.
- Consider creating a custom parameters group for your RDS instance.
- Consider deploying the RDS instance into private subnets.
Once the database switches to the Available state, navigate to Connectivity and Security and copy the endpoint value. We will refer to it as YOUR_RDS_ENDPOINT_URL.
Edit tb-node-db-configmap.yml and replace YOUR_RDS_ENDPOINT_URL and YOUR_RDS_PASSWORD.
4.2 Cassandra (optional)
Section titled “4.2 Cassandra (optional)”Using Cassandra is optional. We recommend it if you plan to insert more than 5K data points per second or want to optimize storage space.
Provision additional node groups
Section titled “Provision additional node groups”Provision additional node groups to host Cassandra instances. At least 4 vCPUs and 16 GB of RAM is recommended.
Create 3 separate node pools with 1 node per zone. Since we use EBS disks, we don’t want K8S to launch a pod in a zone where the corresponding disk is unavailable.
eksctl create nodegroup --config-file=<path> --include='cassandra-*'Deploy Cassandra stateful set
Section titled “Deploy Cassandra stateful set”kubectl apply -f tb-namespace.ymlkubectl config set-context $(kubectl config current-context) --namespace=thingsboardDeploy Cassandra:
kubectl apply -f receipts/cassandra.ymlThe startup may take a few minutes. Monitor the process:
kubectl get podsUpdate DB settings
Section titled “Update DB settings”Edit the ThingsBoard DB settings file and add Cassandra settings. Don’t forget to replace YOUR_AWS_REGION with the name of your AWS region.
echo " DATABASE_TS_TYPE: cassandra" >> tb-node-db-configmap.ymlecho " CASSANDRA_URL: cassandra:9042" >> tb-node-db-configmap.ymlecho " CASSANDRA_LOCAL_DATACENTER: YOUR_AWS_REGION" >> tb-node-db-configmap.ymlVerify:
cat tb-node-db-configmap.yml | grep DATABASE_TS_TYPEExpected output: DATABASE_TS_TYPE: cassandra
Create keyspace
Section titled “Create keyspace”kubectl exec -it cassandra-0 -- bash -c "cqlsh -e \ \"CREATE KEYSPACE IF NOT EXISTS thingsboard \ WITH replication = { \ 'class' : 'NetworkTopologyStrategy', \ 'us-east' : '3' \ };\""Step 5. Obtain and configure license key
Section titled “Step 5. Obtain and configure license key”We assume you have already chosen your subscription plan or decided to purchase a perpetual license. If not, navigate to the pricing page. See How to get pay-as-you-go subscription or How to get perpetual license for details.
Create a docker secret with your license key:
export TB_LICENSE_KEY=PUT_YOUR_LICENSE_KEY_HEREkubectl create -n thingsboard secret generic tb-license --from-literal=license-key=$TB_LICENSE_KEYStep 6. Installation
Section titled “Step 6. Installation”Execute the following command to run the initial setup of the database. This command launches a short-living ThingsBoard pod to provision necessary DB tables, indexes, etc:
./k8s-install-tb.sh --loadDemoWhere --loadDemo is an optional argument to load additional demo data.
After this command finishes you should see:
Installation finished successfully!Step 7. Starting
Section titled “Step 7. Starting”Execute the following command to deploy resources:
./k8s-deploy-resources.shAfter a few minutes, call kubectl get pods. If everything went fine, you should see tb-node-0 pod in the READY state.
Step 8. Configure load balancers
Section titled “Step 8. Configure load balancers”8.1 Configure HTTP(S) load balancer
Section titled “8.1 Configure HTTP(S) load balancer”You have 2 options:
- HTTP — recommended for development. Simple configuration and minimum costs.
- HTTPS — recommended for production. Acts as an SSL termination point with automatic redirect from HTTP to HTTPS.
HTTP load balancer
Section titled “HTTP load balancer”kubectl apply -f receipts/http-load-balancer.ymlCheck the status:
kubectl get ingressOnce provisioned, you should see:
NAME CLASS HOSTS ADDRESS PORTS AGEtb-http-loadbalancer <none> * 34.111.24.134 80 7m25sUse the address to access the HTTP web UI (port 80) and connect devices via HTTP API.
Default credentials:
- System Administrator: [email protected] / sysadmin
- Tenant Administrator: [email protected] / tenant (if demo data loaded)
- Customer User: [email protected] / customer (if demo data loaded)
HTTPS load balancer
Section titled “HTTPS load balancer”Use AWS Certificate Manager to create or import an SSL certificate. Note your certificate ARN.
Edit the load balancer configuration and replace YOUR_HTTPS_CERTIFICATE_ARN with your certificate ARN:
nano receipts/https-load-balancer.ymlDeploy the HTTPS load balancer:
kubectl apply -f receipts/https-load-balancer.yml8.2 Configure MQTT load balancer (optional)
Section titled “8.2 Configure MQTT load balancer (optional)”Configure MQTT load balancer if you plan to use MQTT protocol to connect devices.
kubectl apply -f receipts/mqtt-load-balancer.ymlThe load balancer forwards all TCP traffic for ports 1883 and 8883.
One-way TLS
Section titled “One-way TLS”The simplest way to configure MQTTS is to make the AWS NLB act as a TLS termination point. Traffic between devices and the load balancer is encrypted, while traffic between the load balancer and MQTT Transport is not encrypted. There should be no security issues since the NLB runs in your VPC.
Use AWS Certificate Manager to create or import an SSL certificate. Edit the load balancer configuration:
nano receipts/mqtts-load-balancer.ymlReplace YOUR_MQTTS_CERTIFICATE_ARN with your certificate ARN, then deploy:
kubectl apply -f receipts/mqtts-load-balancer.ymlTwo-way TLS
Section titled “Two-way TLS”Follow the MQTT over SSL guide to create a .pem file. Store it as server.pem in the working directory.
Create a config-map with your PEM file:
kubectl create configmap tb-mqtts-config \ --from-file=server.pem=YOUR_PEM_FILENAME \ --from-file=mqttserver_key.pem=YOUR_PEM_KEY_FILENAME \ -o yaml --dry-run=client | kubectl apply -f -Uncomment all sections in the tb-node.yml file marked with “Uncomment the following lines to enable two-way MQTTS”, then apply:
kubectl apply -f tb-node.ymlDeploy the “transparent” load balancer:
kubectl apply -f receipts/mqtt-load-balancer.yml8.3 Configure UDP load balancer (optional)
Section titled “8.3 Configure UDP load balancer (optional)”Configure UDP load balancer if you plan to use CoAP or LwM2M protocol.
kubectl apply -f receipts/udp-load-balancer.ymlThe load balancer forwards all UDP traffic for ports:
| Port | Protocol |
|---|---|
| 5683 | CoAP non-secure |
| 5684 | CoAP secure DTLS |
| 5685 | LwM2M non-secure |
| 5686 | LwM2M secure DTLS |
| 5687 | LwM2M bootstrap DTLS |
| 5688 | LwM2M bootstrap secure DTLS |
For CoAP over DTLS, follow the CoAP over DTLS guide. For LwM2M over DTLS, follow the LwM2M over DTLS guide.
8.4 Configure Edge load balancer (optional)
Section titled “8.4 Configure Edge load balancer (optional)”Configure the Edge load balancer if you plan to connect Edge instances to your ThingsBoard server.
kubectl apply -f receipts/edge-load-balancer.ymlThe load balancer forwards all TCP traffic on port 7070.
To get the external IP address:
kubectl get services | grep "EXTERNAL-IP\|tb-edge-loadbalancer"Use the external IP address as CLOUD_RPC_HOST in Edge connection parameters.
Step 9. Configure Trendz (optional)
Section titled “Step 9. Configure Trendz (optional)”9.1 Pull Trendz images
Section titled “9.1 Pull Trendz images”docker pull thingsboard/trendz:1.15.1docker pull thingsboard/trendz-python-executor:1.15.19.2 Create a Trendz database in the existing RDS instance
Section titled “9.2 Create a Trendz database in the existing RDS instance”Edit trendz/trendz-secret.yml and replace YOUR_RDS_ENDPOINT_URL and YOUR_RDS_PASSWORD, then apply:
kubectl apply -f ./trendz/trendz-secret.ymlkubectl apply -f ./trendz/trendz-create-db.ymlCheck logs:
kubectl logs job/trendz-create-db -n thingsboard9.3 Trendz starting
Section titled “9.3 Trendz starting”./k8s-deploy-trendz.shAfter this command finishes you should see:
Trendz installed successfully!Step 10. Validate the setup
Section titled “Step 10. Validate the setup”Validate Web UI access
Section titled “Validate Web UI access”Get the DNS name of the HTTP load balancer:
kubectl get ingressUse the address to open the ThingsBoard web interface in your browser.
Default credentials:
- System Administrator: [email protected] / sysadmin
- Tenant Administrator: [email protected] / tenant (if demo data loaded)
- Customer User: [email protected] / customer (if demo data loaded)
Validate MQTT/CoAP access
Section titled “Validate MQTT/CoAP access”Get the load balancer services:
kubectl get serviceTwo load balancers are available:
tb-mqtt-loadbalancer-external— for MQTT protocoltb-coap-loadbalancer-external— for CoAP protocol
Use the EXTERNAL-IP field of the load balancers to connect to the cluster.
Troubleshooting
Section titled “Troubleshooting”To examine ThingsBoard node logs:
kubectl logs -f tb-node-0Other useful commands:
kubectl get pods— see the state of all podskubectl get services— see the state of all serviceskubectl get deployments— see the state of all deployments
See the kubectl Cheat Sheet for more details.
Upgrading
Section titled “Upgrading”Upgrading to new ThingsBoard version
Section titled “Upgrading to new ThingsBoard version”Merge your local changes with the latest release branch from the repo you cloned in Step 1.
If a database upgrade is needed:
./k8s-upgrade-tb.sh --fromVersion=[FROM_VERSION]Where FROM_VERSION is the starting version. See Upgrade Instructions for valid fromVersion values. You must upgrade versions one by one (e.g., 3.6.1 → 3.6.2 → 3.6.3).
Once completed, re-deploy resources:
./k8s-deploy-resources.shUpgrading to new Trendz version (optional)
Section titled “Upgrading to new Trendz version (optional)”Pull the latest changes:
git pull origin masterThen execute:
./k8s-upgrade-trendz.shCluster deletion
Section titled “Cluster deletion”Delete all ThingsBoard pods:
./k8s-delete-resources.shDelete all ThingsBoard pods and configmaps:
./k8s-delete-all.shDelete the EKS cluster (change cluster name and region as needed):
eksctl delete cluster -r us-east-1 -n thingsboard -w