使用 Helm 部署 TDengine 集群

    Helm 会使用 kubectl 和 kubeconfig 的配置来操作 Kubernetes,可以参考 Rancher 安装 Kubernetes 的配置来进行设置。

    安装 TDengine Chart

    TDengine Chart 尚未发布到 Helm 仓库,当前可以从 GitHub 直接下载:

    获取当前 Kubernetes 的存储类:

    1. kubectl get storageclass

    在 minikube 默认为 standard.

    之后,使用 helm 命令安装:

    1. helm install tdengine tdengine-3.0.2.tgz \
    2. --set storage.className=<your storage class name>

    在 minikube 环境下,可以设置一个较小的容量避免超出磁盘可用空间:

    1. export POD_NAME=$(kubectl get pods --namespace default \
    2. -l "app.kubernetes.io/name=tdengine,app.kubernetes.io/instance=tdengine" \
    3. -o jsonpath="{.items[0].metadata.name}")
    4. kubectl --namespace default exec $POD_NAME -- taos -s "show dnodes; show mnodes"
    5. kubectl --namespace default exec -it $POD_NAME -- taos

    可以创建一个表进行测试:

    1. kubectl --namespace default exec $POD_NAME -- \
    2. taos -s "create database test;
    3. use test;
    4. create table t1 (ts timestamp, n int);
    5. insert into t1 values(now, 1)(now + 1s, 2);
    6. select * from t1;"

    TDengine 支持 values.yaml 自定义。

    通过 helm show values 可以获取 TDengine Chart 支持的全部 values 列表:

    1. helm show values tdengine-3.0.2.tgz

    你可以将结果保存为 values.yaml,之后可以修改其中的各项参数,如 replica 数量,存储类名称,容量大小,TDengine 配置等,然后使用如下命令安装 TDengine 集群:

    全部参数如下:

    1. # Default values for tdengine.
    2. # This is a YAML-formatted file.
    3. # Declare variables to be passed into helm templates.
    4. replicaCount: 1
    5. image:
    6. prefix: tdengine/tdengine
    7. #pullPolicy: Always
    8. # Overrides the image tag whose default is the chart appVersion.
    9. # tag: "3.0.2.0"
    10. service:
    11. # ClusterIP is the default service type, use NodeIP only if you know what you are doing.
    12. type: ClusterIP
    13. ports:
    14. # TCP range required
    15. tcp: [6030, 6041, 6042, 6043, 6044, 6046, 6047, 6048, 6049, 6060]
    16. # UDP range
    17. udp: [6044, 6045]
    18. # Set timezone here, not in taoscfg
    19. timezone: "Asia/Shanghai"
    20. resources:
    21. # We usually recommend not to specify default resources and to leave this as a conscious
    22. # choice for the user. This also increases chances charts run on environments with little
    23. # resources, such as Minikube. If you do want to specify resources, uncomment the following
    24. # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
    25. # limits:
    26. # cpu: 100m
    27. # memory: 128Mi
    28. # requests:
    29. # memory: 128Mi
    30. storage:
    31. # Set storageClassName for pvc. K8s use default storage class if not set.
    32. className: ""
    33. dataSize: "100Gi"
    34. logSize: "10Gi"
    35. nodeSelectors:
    36. taosd:
    37. # node selectors
    38. clusterDomainSuffix: ""
    39. # Config settings in taos.cfg file.
    40. #
    41. # The helm/k8s support will use environment variables for taos.cfg,
    42. # converting an upper-snake-cased variable like `TAOS_DEBUG_FLAG`,
    43. # to a camelCase taos config variable `debugFlag`.
    44. #
    45. # See the variable list at https://www.taosdata.com/cn/documentation/administrator .
    46. #
    47. # Note:
    48. # 1. firstEp/secondEp: should not be set here, it's auto generated at scale-up.
    49. # 2. serverPort: should not be set, we'll use the default 6030 in many places.
    50. # 3. fqdn: will be auto generated in kubernetes, user should not care about it.
    51. # 4. role: currently role is not supported - every node is able to be mnode and vnode.
    52. #
    53. # Btw, keep quotes "" around the value like below, even the value will be number or not.
    54. taoscfg:
    55. # Starts as cluster or not, must be 0 or 1.
    56. # 0: all pods will start as a separate TDengine server
    57. # 1: pods will start as TDengine server cluster. [default]
    58. CLUSTER: "1"
    59. # number of replications, for cluster only
    60. TAOS_REPLICA: "1"
    61. # TAOS_NUM_OF_RPC_THREADS: number of threads for RPC
    62. #TAOS_NUM_OF_RPC_THREADS: "2"
    63. #
    64. # TAOS_NUM_OF_COMMIT_THREADS: number of threads to commit cache data
    65. #TAOS_NUM_OF_COMMIT_THREADS: "4"
    66. # enable/disable installation / usage report
    67. #TAOS_TELEMETRY_REPORTING: "1"
    68. # time interval of system monitor, seconds
    69. #TAOS_MONITOR_INTERVAL: "30"
    70. # time interval of dnode status reporting to mnode, seconds, for cluster only
    71. #TAOS_STATUS_INTERVAL: "1"
    72. # time interval of heart beat from shell to dnode, seconds
    73. #TAOS_SHELL_ACTIVITY_TIMER: "3"
    74. # minimum sliding window time, milli-second
    75. #TAOS_MIN_SLIDING_TIME: "10"
    76. # minimum time window, milli-second
    77. #TAOS_MIN_INTERVAL_TIME: "1"
    78. # the compressed rpc message, option:
    79. # -1 (no compression)
    80. # 0 (all message compressed),
    81. # > 0 (rpc message body which larger than this value will be compressed)
    82. #TAOS_COMPRESS_MSG_SIZE: "-1"
    83. # max number of connections allowed in dnode
    84. #TAOS_MAX_SHELL_CONNS: "50000"
    85. # stop writing logs when the disk size of the log folder is less than this value
    86. #TAOS_MINIMAL_LOG_DIR_G_B: "0.1"
    87. # stop writing temporary files when the disk size of the tmp folder is less than this value
    88. #TAOS_MINIMAL_TMP_DIR_G_B: "0.1"
    89. # if disk free space is less than this value, taosd service exit directly within startup process
    90. #TAOS_MINIMAL_DATA_DIR_G_B: "0.1"
    91. # One mnode is equal to the number of vnode consumed
    92. #TAOS_MNODE_EQUAL_VNODE_NUM: "4"
    93. # enbale/disable http service
    94. #TAOS_HTTP: "1"
    95. # enable/disable system monitor
    96. #TAOS_MONITOR: "1"
    97. # enable/disable async log
    98. #TAOS_ASYNC_LOG: "1"
    99. #
    100. # time of keeping log files, days
    101. #TAOS_LOG_KEEP_DAYS: "0"
    102. # The following parameters are used for debug purpose only.
    103. # debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR
    104. # 131: output warning and error
    105. # 135: output debug, warning and error
    106. # 143: output trace, debug, warning and error to log
    107. # 199: output debug, warning and error to both screen and file
    108. # 207: output trace, debug, warning and error to both screen and file
    109. #
    110. # debug flag for all log type, take effect when non-zero value\
    111. #TAOS_DEBUG_FLAG: "143"
    112. # generate core file when service crash
    113. #TAOS_ENABLE_CORE_FILE: "1"

    扩容

    关于扩容可参考上一节的说明,有一些额外的操作需要从 helm 的部署中获取。

    1. export STS_NAME=$(kubectl get statefulset \
    2. -l "app.kubernetes.io/name=tdengine" \
    3. -o jsonpath="{.items[0].metadata.name}")

    扩容操作极其简单,增加 replica 即可。以下命令将 TDengine 扩充到三节点:

    1. kubectl scale --replicas 3 statefulset/$STS_NAME

    使用命令 show dnodes 和 检查是否扩容成功。

    warning

    缩容操作并没有完整测试,可能造成数据风险,请谨慎使用。

    获取需要缩容的 dnode 列表,并手动 Drop。

    清理集群

    Helm 管理下,清理操作也变得简单:

      但 Helm 也不会自动移除 PVC,需要手动获取 PVC 然后删除掉。