Kubernetes安装ThingsBoard (on Google Cloud Platform)

This guide will help you to deploy ThingsBoard into a cluster on Google Cloud Platform using Kubernetes.

本章描述如何使用Kubernetes在谷歌云平台上将ThingsBoard部署到到一个集群中。

安装步骤

  • Install Cloud SDK
  • Make sure that you have Google Cloud Platform account activated and you have sufficient funds to create clusters and provision instances.
  • Download the following files from thingsboard repo:
    1. **common.yaml - Kubernetes config file for common resources (StorageClass etc.).
    2. **cassandra.yaml - Kubernetes config file for Cassandra Service. By Default start 2 nodes.
    3. **zookeeper.yaml - Kubernetes config file for ZK Service. By Default start 3 nodes.
    4. **tb.yaml - Kubernetes config file for ThingsBoard Service. By Default starts 2 nodes.
    5. **cassandra-setup.yaml - Kubernetes config file for Pod that creates ThingsBoard keyspace and tables inside Cassandra storage.
  • 安装Cloud SDK
  • 确保您的Google Cloud Platform帐户被激活,并且您有足够的资金来创建集群以及置备实例。
  • 从ThingsBoard repo中下载以下文件:
    1. common.yaml - 用于公共资源的Kubernetes配置文件(StorageClass等)。
    2. cassandra.yaml - 用于Cassandra服务的Kubernetes配置文件,默认启动2个节点。
    3. zookeeper.yaml - 用于ZK服务的Kubernetes配置文件,默认启动3个节点。
    4. tb.yaml - 用于ThingsBoard服务的Kubernetes配置文件,默认启动2个节点。
    5. cassandra-setup.yaml - 用于Pod(在Cassandr存储空间中创建ThingBoard密匙和表)的配置文件。
curl -L https://raw.githubusercontent.com/thingsboard/thingsboard/release-1.3/docker/k8s/common.yaml > common.yaml
curl -L https://raw.githubusercontent.com/thingsboard/thingsboard/release-1.3/docker/k8s/cassandra.yaml > cassandra.yaml
curl -L https://raw.githubusercontent.com/thingsboard/thingsboard/release-1.3/docker/k8s/zookeeper.yaml > zookeeper.yaml
curl -L https://raw.githubusercontent.com/thingsboard/thingsboard/release-1.3/docker/k8s/tb.yaml > tb.yaml
curl -L https://raw.githubusercontent.com/thingsboard/thingsboard/release-1.3/docker/k8s/cassandra-setup.yaml > cassandra-setup.yaml
  • Check server config to get available kubernetes cluster versions:

检查服务器配置,获取可用的kubernetes集群版本:

gcloud container get-server-config

  • The output will be similar to:

输出结果类似如下显示内容:

Fetching server config for us-east1-b
defaultClusterVersion: 1.6.4
defaultImageType: COS
validImageTypes:
- COS
- CONTAINER_VM
validMasterVersions:
- 1.7.1
- 1.6.7
- 1.6.4
validNodeVersions:
- 1.7.1
- 1.7.0
- 1.6.7
- 1.6.6
- 1.6.4
- 1.5.7
- 1.4.9
  • Create cluster using gcloud cli (for demo purpose 6 standard nodes are going to be deployed for cluster pods). Select from the list above validMasterVersions that is higher than 1.6.2 (VALID_MASTER_VERSION) and create cluster:

使用gcloud cli创建集群(建议在集群pods中部署6个标准节点用作演示)。使用以上列表中validMasterVersions版本高于1.6.2的(VALID_MASTER_VERSION)并创建集群:

gcloud container clusters create YOUR_CLUSTER_NAME --cluster-version=VALID_MASTER_VERSION --node-labels=machinetype=tb --num-nodes=2
  • Create additional node pool for Cassandra and Zookeeper PODs:

为Cassandra and Zookeeper PODs创建额外的节点池。

gcloud container node-pools create cassandra-pool --cluster=YOUR_CLUSTER_NAME --node-labels=machinetype=other --num-nodes=3 --disk-size=10
  • Create the default credentials file on your local machine:

为本地机器创建默认凭证文件:

gcloud auth application-default login
  • Create common resources that are used by other resources:

创建其他资源使用的公共资源:

kubectl create -f common.yaml

  • Provision cassandra cluster:

配置cassandra集群:

kubectl create -f cassandra.yaml

  • Monitor provisioning of Cassandra Pods by executing following command:

执行以下命令监控Cassandra Pods配置:

kubectl get pods -w -l app=cassandra

Please wait until all 2 Pods of Cassandra service become Running:

请等待Cassandra服务的2个Pods运行:

NAME             READY     STATUS    RESTARTS   AGE
cassandra-0      1/1       Running   0          5s
cassandra-1      1/1       Running   0          3s
  • Once Cassandra Pods are running please provision Pod that will create ThingsBoard schema and tables inside Cassandra storage:

Pods运行时,请配置在Cassandra存储空间内创建ThingBoard shcema和表的pod:

kubectl create -f cassandra-setup.yaml

  • Check logs of the cassandra setup node:

查阅cassandra设置节点日志:

kubectl logs -f cassandra-setup

  • Wait for successful installation message:

等待安装成功信息:

Adding group `thingsboard' (GID 102) ...
Done.
Unpacking thingsboard (1.3.0-1) ...
Setting up thingsboard (1.3.0-1) ...
9042/tcp open  unknown
Creating 'ThingsBoard' schema and system data...
plus demo data...
 ===================================================
 :: ThingsBoard ::       (v1.3.0)
 ===================================================

log4j:WARN No appenders could be found for logger (hsqldb.db.HSQLDB5D8345905E.ENGINE).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Starting ThingsBoard Installation...
Installing DataBase schema...
Installing SQL DataBase schema...
Loading system data...
Loading demo data...
Installation finished successfully!
ThingsBoard installed successfully!
  • Provision zookeeper Service:

kubectl create -f zookeeper.yaml

  • Provision ThingsBoard Service:

kubectl create -f tb.yaml

  • Execute the next command to see the status of ThingsBoard Pods:

执行如下命令查看ThingsBoard Pods状态:

kubectl get pods -w -l app=tb

ThingsBoard Pods should become into Running status:

ThingsBoard Pods应该变为运行状态:

NAME      READY     STATUS    RESTARTS   AGE
tb-0      1/1       Running   0          5s
tb-1      1/1       Running   0          3s
  • Once ThingsBoard Pods are in ‘Running’ status check logs of the first Pod to make sure that everything is OK:

ThingsBoard Pods为运行状态时,请检查第一个Pod日志确保未出现任何异常:

kubectl logs -f tb-0

  • ThingsBoard container is successfully started once similar line appears in the log:

如果日志中出现类似如下信息则表示ThingsBoard启动成功:

2016-12-13 13:44:52,407 [main] INFO  o.t.s.ThingsboardServerApplication - Started ThingsboardServerApplication in 113.64 seconds (JVM running for 118.624)

To obtain external IP of ThingsBoard Service execute:

获得ThingsBoard服务的外部IP执行:

kubectl get services tb-service

  • In the response something similar should appear:

回应信息应显示如下信息(类似):

NAME             CLUSTER-IP     EXTERNAL-IP    PORT(S)                                        AGE
tb-service      10.3.251.137   35.185.81.65   8080:31099/TCP,1883:32314/TCP,5683:30062/TCP   1m

Now you are able to open Web UI using following link:

现在可以使用如下链接打开Web页面了:

http://EXTERNAL-IP:8080/

  • To delete the entire cluster execute the following command:

执行以下命令删除整个集群:

gcloud container clusters delete YOUR_CLUSTER_NAME

高级应用

common.yaml file

Common Kubernetes config file common.yaml contains next set of cloud resources:

公共Kubernetes配置文件common.yaml包含下一组云资源:

  • StorageClass. These resources are used by Cassandra and ZK Services as volume storage definitions
  • StorageClass.

cassandra.yaml file

Cassandra Kubernetes config file cassandra.yaml contains next set of cloud resources:

  • Headless Service. Service exposes 9042 port for the Cassandra Pods and guarantees network identity for them.
  • StatefulSet. Set is responsible for provisioning Cassandra Pods onto Cloud Nodes.
    1. podAntiAffinity. This property guarantees that Cassandra Pods are deployed to different Nodes.

zookeeper.yaml file

Zookeeper Kubernetes config file zookeeper.yaml contains next set of cloud resources:

  • Headless Service. Service exposes 2888 and 3888 ports for the ZK Pods and guarantees network identity for them.
  • ConfigMap. Contains set of configurations options that are pushed into ZK images.
  • PodDisruptionBudget. Guarantees minimum instances of the cluster that must be up and running.
  • StatefulSet. Set is responsible for provisioning ZK Pods onto Cloud Nodes.
    1. podAntiAffinity. This property guarantees that ZK Pods are deployed to different Nodes.

tb.yaml file

ThingsBoard Kubernetes config file tb.yaml contains next set of cloud resources:

  • Loadbalancer Service. Service that exposes 8080, 1883 and 5683 ports of ThingsBoard cluster to external world using external IP.
  • ConfigMap. Contains set of configurations options that are pushed into ThingsBoard images.
  • PodDisruptionBudget. Guarantees minimum instances of the cluster that must be up and running.
  • StatefulSet. Set is responsible for provisioning ThingsBoard Pods onto Cloud Nodes.
    1. podAntiAffinity. This property guarantees that ThingsBoard Pods are deployed to different Nodes.

cassandra-setup.yaml

ThingsBoard Kubernetes config file cassandra-setup.yaml contains next set of cloud resources:

  • Pod that runs once and creates ThingsBoard keyspace and tables inside Cassandra storage

results matching ""

    No results matching ""