GKE Microservices Setup
This guide walks you through deploying ThingsBoard in microservices mode on Google Kubernetes Engine. We use Google Cloud SQL for managed PostgreSQL.
Prerequisites
Section titled “Prerequisites”Install and Configure Tools
Section titled “Install and Configure Tools”Install kubectl and gcloud. See before you begin for more info.
Create a new GCP project (recommended) or choose an existing one:
gcloud initEnable GCP Services
Section titled “Enable GCP Services”gcloud services enable container.googleapis.com sql-component.googleapis.com sqladmin.googleapis.comPull ThingsBoard Images
Section titled “Pull ThingsBoard Images”Verify that you can pull the images from Docker Hub:
docker pull thingsboard/tb-node:4.4.0docker pull thingsboard/tb-web-report:4.4.0docker pull thingsboard/tb-web-ui:4.4.0docker pull thingsboard/tb-js-executor:4.4.0docker pull thingsboard/tb-http-transport:4.4.0docker pull thingsboard/tb-mqtt-transport:4.4.0docker pull thingsboard/tb-coap-transport:4.4.0docker pull thingsboard/tb-lwm2m-transport:4.4.0docker pull thingsboard/tb-snmp-transport:4.4.0docker pull thingsboard/tb-integration-executor:4.4.0Step 1. Clone ThingsBoard K8S Scripts Repository
Section titled “Step 1. Clone ThingsBoard K8S Scripts Repository”Clone the repository containing the Kubernetes deployment scripts:
git clone -b release-4.4.0 https://github.com/thingsboard/thingsboard-pe-k8s.git --depth 1cd thingsboard-pe-k8s/gcp/microservicesStep 2. Define Environment Variables
Section titled “Step 2. Define Environment Variables”export GCP_PROJECT=$(gcloud config get-value project)export GCP_REGION=us-central1export GCP_ZONE=us-central1export GCP_ZONE1=us-central1-aexport GCP_ZONE2=us-central1-bexport GCP_ZONE3=us-central1-cexport GCP_NETWORK=defaultexport TB_CLUSTER_NAME=tb-msaexport TB_DATABASE_NAME=tb-dbecho "Project: $GCP_PROJECT, region: $GCP_REGION, zones: $GCP_ZONE1,$GCP_ZONE2,$GCP_ZONE3, network: $GCP_NETWORK, cluster: $TB_CLUSTER_NAME, database: $TB_DATABASE_NAME"| Variable | Default | Description |
|---|---|---|
GCP_PROJECT |
(auto-detected) | Your GCP project ID |
GCP_REGION |
us-central1 |
Compute region |
GCP_ZONE1/2/3 |
us-central1-a/b/c |
Availability zones for the regional cluster |
GCP_NETWORK |
default |
GCP network name |
TB_CLUSTER_NAME |
tb-msa |
GKE cluster name |
TB_DATABASE_NAME |
tb-db |
Cloud SQL instance name |
Step 3. Configure and Create GKE Cluster
Section titled “Step 3. Configure and Create GKE Cluster”Create a regional cluster distributed across 3 zones. The example provisions one e2-standard-4 node per zone (3 nodes total). You can modify the machine type and node count to suit your workload. See GCP machine types for options.
gcloud container clusters create $TB_CLUSTER_NAME \ --release-channel stable \ --region $GCP_REGION \ --network=$GCP_NETWORK \ --node-locations $GCP_ZONE1,$GCP_ZONE2,$GCP_ZONE3 \ --enable-ip-alias \ --num-nodes=1 \ --node-labels=role=main \ --machine-type=e2-standard-4Alternatively, see the regional cluster setup guide.
Step 4. Update the Context of kubectl
Section titled “Step 4. Update the Context of kubectl”gcloud container clusters get-credentials $TB_CLUSTER_NAME --region $GCP_REGIONStep 5. Provision Databases
Section titled “Step 5. Provision Databases”5.1 Google Cloud SQL (PostgreSQL) Instance
Section titled “5.1 Google Cloud SQL (PostgreSQL) Instance”Prerequisites
Section titled “Prerequisites”Enable service networking:
gcloud services enable servicenetworking.googleapis.com --project=$GCP_PROJECT
gcloud compute addresses create google-managed-services-$GCP_NETWORK \ --global \ --purpose=VPC_PEERING \ --prefix-length=16 \ --network=projects/$GCP_PROJECT/global/networks/$GCP_NETWORK
gcloud services vpc-peerings connect \ --service=servicenetworking.googleapis.com \ --ranges=google-managed-services-$GCP_NETWORK \ --network=$GCP_NETWORK \ --project=$GCP_PROJECTCreate Database Server Instance
Section titled “Create Database Server Instance”gcloud beta sql instances create $TB_DATABASE_NAME \ --database-version=POSTGRES_16 \ --region=$GCP_REGION --availability-type=regional \ --no-assign-ip --network=projects/$GCP_PROJECT/global/networks/$GCP_NETWORK \ --cpu=2 --memory=7680MBNote the IP address (YOUR_DB_IP_ADDRESS) from the command output.
Set Database Password
Section titled “Set Database Password”gcloud sql users set-password postgres \ --instance=$TB_DATABASE_NAME \ --password=secretCreate Database
Section titled “Create Database”gcloud sql databases create thingsboard --instance=$TB_DATABASE_NAME5.2 Cassandra (Optional)
Section titled “5.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”Create 3 separate node pools with 1 node per zone. At least 4 vCPUs and 16 GB of RAM is recommended.
gcloud container node-pools create cassandra1 --cluster=$TB_CLUSTER_NAME --zone=$GCP_ZONE --node-locations=$GCP_ZONE1 \ --node-labels=role=cassandra --num-nodes=1 --min-nodes=1 --max-nodes=1 --machine-type=e2-standard-4gcloud container node-pools create cassandra2 --cluster=$TB_CLUSTER_NAME --zone=$GCP_ZONE --node-locations=$GCP_ZONE2 \ --node-labels=role=cassandra --num-nodes=1 --min-nodes=1 --max-nodes=1 --machine-type=e2-standard-4gcloud container node-pools create cassandra3 --cluster=$TB_CLUSTER_NAME --zone=$GCP_ZONE --node-locations=$GCP_ZONE3 \ --node-labels=role=cassandra --num-nodes=1 --min-nodes=1 --max-nodes=1 --machine-type=e2-standard-4Deploy Cassandra Stateful Set
Section titled “Deploy Cassandra Stateful Set”Create the namespace, then deploy Cassandra:
kubectl apply -f tb-namespace.ymlkubectl config set-context $(kubectl config current-context) --namespace=thingsboardkubectl apply -f receipts/cassandra.ymlUpdate DB Settings
Section titled “Update DB Settings”echo " DATABASE_TS_TYPE: cassandra" >> tb-node-db-configmap.ymlecho " CASSANDRA_URL: cassandra:9042" >> tb-node-db-configmap.ymlecho " CASSANDRA_LOCAL_DATACENTER: $GCP_REGION" >> tb-node-db-configmap.ymlCreate Keyspace
Section titled “Create Keyspace”Create the ThingsBoard keyspace inside Cassandra:
kubectl exec -it cassandra-0 -- bash -c "cqlsh -e \ \"CREATE KEYSPACE IF NOT EXISTS thingsboard \ WITH replication = { \ 'class' : 'NetworkTopologyStrategy', \ 'us-central1' : '3' \ };\""Step 6. Obtain and Configure License Key
Section titled “Step 6. 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.
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 7. Installation
Section titled “Step 7. Installation”Edit tb-node-db-configmap.yml and replace YOUR_DB_IP_ADDRESS and YOUR_DB_PASSWORD:
nano tb-node-db-configmap.ymlRun the installation:
./k8s-install-tb.shAfter this command finishes you should see:
Installation finished successfully!Step 8. Starting
Section titled “Step 8. Starting”Deploy thirdparty components (Zookeeper, Kafka, Redis) and main ThingsBoard microservices:
./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.
Deploy Transport Microservices
Section titled “Deploy Transport Microservices”Deploy the transport microservices you need. Omit protocols you don’t use to save resources:
# HTTP Transport (optional)kubectl apply -f transports/tb-http-transport.yml
# MQTT Transport (optional)kubectl apply -f transports/tb-mqtt-transport.yml
# CoAP Transport (optional)kubectl apply -f transports/tb-coap-transport.yml
# LwM2M Transport (optional)kubectl apply -f transports/tb-lwm2m-transport.yml
# SNMP Transport (optional)kubectl apply -f transports/tb-snmp-transport.ymlStep 9. Configure Load Balancers
Section titled “Step 9. Configure Load Balancers”9.1 Configure HTTP(S) Load Balancer
Section titled “9.1 Configure HTTP(S) Load Balancer”You have 3 options:
- HTTP — recommended for development.
- HTTPS — recommended for production. Uses Google-managed SSL certificate.
- Transparent — forwards traffic to ThingsBoard HTTP/HTTPS ports. Requires your own SSL certificate.
kubectl apply -f receipts/http-load-balancer.ymlCheck the status:
kubectl get ingressUse the address to access the web UI and connect devices via HTTP API.
Administrator account creation on first access is covered next, in Step 10. Create Your Administrator Account.
See the official documentation for Google-managed SSL certificates. Reserve a static IP:
gcloud compute addresses create thingsboard-http-lb-address --globalEdit receipts/https-load-balancer.yml and replace PUT_YOUR_DOMAIN_HERE, then deploy:
kubectl apply -f receipts/https-load-balancer.ymlAssign the domain name to the load balancer IP and wait for the certificate to provision (up to 60 minutes):
kubectl describe managedcertificate managed-certFollow the HTTPS (TLS) configuration guide to configure SSL in tb-node.yml. Then deploy:
kubectl apply -f receipts/transparent-http-load-balancer.yml9.2 Configure MQTT Load Balancer (Optional)
Section titled “9.2 Configure MQTT Load Balancer (Optional)”kubectl apply -f receipts/mqtt-load-balancer.ymlThe load balancer forwards all TCP traffic for ports 1883 and 8883.
For MQTT over SSL, follow the MQTT over SSL guide to configure transport/tb-mqtt-transport.yml.
9.3 Configure CoAP Load Balancer (Optional)
Section titled “9.3 Configure CoAP Load Balancer (Optional)”kubectl apply -f receipts/coap-load-balancer.ymlThe load balancer forwards UDP traffic for ports 5683 (CoAP non-secure) and 5684 (CoAP secure DTLS).
For CoAP over DTLS, follow the CoAP over DTLS guide to configure transport/tb-coap-transport.yml.
9.4 Configure LwM2M Load Balancer (Optional)
Section titled “9.4 Configure LwM2M Load Balancer (Optional)”kubectl apply -f receipts/lwm2m-load-balancer.ymlThe load balancer forwards UDP traffic for ports 5685–5688.
For LwM2M over DTLS, follow the LwM2M over DTLS guide to configure transport/tb-lwm2m-transport.yml.
9.5 Configure Edge Load Balancer (Optional)
Section titled “9.5 Configure Edge Load Balancer (Optional)”kubectl apply -f receipts/edge-load-balancer.ymlThe load balancer forwards all TCP traffic on port 7070.
Step 10. Create Your Administrator Account
Section titled “Step 10. Create Your Administrator Account”After launching ThingsBoard, open the web UI at the load balancer address. ThingsBoard prompts you to create your System Administrator account — the account that manages the platform itself (tenants, system settings, platform-wide resources).
- Enter Email, Password, and Confirm password.
- The Set up a demo tenant option is selected by default: it creates a ready-made tenant with dashboards, devices, and rule chains for exploring the platform before building your own solution. Clear it if you want to start with an empty platform.
- Click Create account. You are signed in as the system administrator.
Your ThingsBoard instance is now installed and running.
Validate the Setup
Section titled “Validate the Setup”Confirm that the load balancers created in Step 9 are provisioned and reachable, and note their addresses — you need them to open the web UI and to connect devices.
Validate Web UI Access
Section titled “Validate Web UI Access”Check the status of the ingress you created for the HTTP(S) load balancer:
kubectl get ingressOnce an external IP address is assigned, use it to open the ThingsBoard web interface in your browser.
Validate MQTT/CoAP Access
Section titled “Validate MQTT/CoAP Access”List the cluster services to find the external IP addresses assigned to the transport load balancers you configured:
kubectl get serviceUse the external IP of each load balancer to connect devices over MQTT, CoAP, LwM2M, or Edge.
[Optional] Configure Trendz Analytics
Section titled “[Optional] Configure Trendz Analytics”Pull Trendz Images
Section titled “Pull Trendz Images”Pull the Trendz images from Docker Hub:
docker pull thingsboard/trendz:1.16.0docker pull thingsboard/trendz-python-executor:1.16.0Create a Trendz Database in the Existing Cloud SQL Instance
Section titled “Create a Trendz Database in the Existing Cloud SQL Instance”Edit trendz/trendz-secret.yml and replace YOUR_DB_IP_ADDRESS and YOUR_DB_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 thingsboardDeploy Trendz
Section titled “Deploy Trendz”./k8s-deploy-trendz.shAfter this command finishes you should see:
Trendz installed successfully!Troubleshooting
Section titled “Troubleshooting”Stream the logs of the ThingsBoard node pod to diagnose startup or runtime issues:
kubectl logs -f tb-node-0See the kubectl Cheat Sheet for more details.
Cluster Deletion
Section titled “Cluster Deletion”Delete ThingsBoard pods and load balancers:
./k8s-delete-resources.shDelete all data including database:
./k8s-delete-all.shNext Steps
Section titled “Next Steps”With ThingsBoard running, these concept guides help you build your first solution:
- Getting Started — a guided walkthrough of the platform after installation.
- Multi-Tenancy & Hierarchy — how tenants, customers, and users are organized.
- Digital Twin Model — how devices and assets are modeled in the platform.
- Data Processing — how the Rule Engine transforms and routes incoming data.
- Alarms & Notifications — how to detect conditions and notify users.
- Data Visualization — how to build dashboards and widgets.
Was this helpful?