TDEngine 集群安装 (K8S)

2023-05-16

1. 构建镜像

1.1 entrypoint.sh

#!/bin/bash

set +e
ulimit -c unlimited
sysctl -w kernel.core_pattern=/corefile/core-%e-%p

if [ "x$TZ" != "x" ]; then
    ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
fi

if [ "$TAOS_FQDN" = "" ]; then
    echo "TAOS_FQDN not set"
    exit 1
fi

sed -i "s#.*fqdn.*#fqdn    ${TAOS_FQDN}#" /etc/taos/taos.cfg
if [ $? -ne 0 ]; then
    echo "refreshing fqdn failed"
    exit 1
fi

if [ "x$TAOS_FIRST_EP" != "x" ]; then
    sed -i "s#.*firstEp.*#firstEp     ${TAOS_FIRST_EP}#" /etc/taos/taos.cfg
    if [ $? -ne 0 ]; then
        echo "refreshing firstEp failed"
        exit 1
    fi
fi

if [ "x$TAOS_SERVER_PORT" != "x" ]; then
    sed -i "s#.*serverPort.*#serverPort     ${TAOS_SERVER_PORT}#" /etc/taos/taos.cfg
    if [ $? -ne 0 ]; then
        echo "refreshing serverPort failed"
        exit 1
    fi
fi


CLUSTER=${CLUSTER:=}
FIRST_EP_HOST=${TAOS_FIRST_EP%:*}
SERVER_PORT=${TAOS_SERVER_PORT:-6030}


if [ "$CLUSTER" = "" ]; then
    # single node
    $@
elif [ "$TAOS_FQDN" = "$FIRST_EP_HOST" ] ; then
    # master node
    $@
else
    # follower, wait for master node ready
    while true
    do
        taos -h $FIRST_EP_HOST -n startup > /dev/null
        if [ $? -eq 0 ]; then
            taos -h $FIRST_EP_HOST -s "create dnode \"$TAOS_FQDN:$SERVER_PORT\";"
            break
        fi
        sleep 1s
    done

    $@
fi

1.2 Dockerfile

通过源码方式构建镜像,同时支持 AMD64 & ARM64 系统

FROM ubuntu:18.04 as builder
RUN apt-get update \
    && apt-get install -y gcc cmake build-essential git wget  \
    && apt-get clean \
    && cd /usr/local/src \
    && wget https://github.com/taosdata/TDengine/archive/refs/tags/ver-2.4.0.0.tar.gz \
    && tar zxvf ver-2.4.0.0.tar.gz && cd TDengine-ver-2.4.0.0 \
    && mkdir debug && cd debug \
    && cmake .. && cmake --build . && make install
WORKDIR /root


FROM ubuntu:18.04
LABEL MAINTAINER="eli.he@outlook.com>"

COPY ./entrypoint.sh /usr/bin/
COPY --from=0 /usr/local/taos /usr/local/taos
COPY --from=0 /etc/taos /etc/taos

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
    && apt-get install -y apt-utils locales tzdata curl wget net-tools iproute2 iputils-ping sysstat binutils \
    && locale-gen en_US.UTF-8 \
    && apt-get clean \
    && chmod +x /usr/bin/entrypoint.sh \
    && ln -s /usr/local/taos/bin/taos /usr/bin/taos \
    && ln -s /usr/local/taos/bin/taosd       /usr/bin/taosd \
    && ln -s /usr/local/taos/bin/taosdump    /usr/bin/taosdump \
    && ln -s /usr/local/taos/bin/taosdemo    /usr/bin/taosdemo \
    && ln -s /usr/local/taos/bin/remove.sh   /usr/bin/rmtaos \
    && ln -s /usr/local/taos/include/taoserror.h  /usr/include/taoserror.h \
    && ln -s /usr/local/taos/include/taos.h  /usr/include/taos.h \
    && ln -s /usr/local/taos/driver/libtaos.so.2.4.0.0  /usr/lib/libtaos.so.1 \
    && ln -s /usr/lib/libtaos.so.1 /usr/lib/libtaos.so  \
    && mkdir -p /var/lib/taos \
    && mkdir -p /var/log/taos \
    && chmod 777 /var/log/taos

ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8

WORKDIR /etc/taos
EXPOSE 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042
CMD ["taosd"]
VOLUME [ "/var/lib/taos", "/var/log/taos", "/corefile" ]
ENTRYPOINT [ "/usr/bin/entrypoint.sh" ]

1.3 生成镜像

docker build -t tdengine:2.4.0.0 .

2. 安装集群

2.1 创建 namespace

$ mkdir ~/taos && cd $_

$ cat > taos-namespace.yml <<EOF
apiVersion: v1
kind: Namespace
metadata:
  name: taos-cluster
EOF

$ kubectl apply -f taos-namespace.yml
$ kubectl get ns
taos-cluster     Active   7s

2.2 创建 ConfigMap

$ cat > taos-configmap.yml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
  name: taos-cfg
  namespace: taos-cluster
  labels:
    app: tdengine
data:
  CLUSTER: "1"
  TAOS_KEEP: "3650"
  TAOS_DEBUG_FLAG: "135"
EOF

$ kubectl apply -f taos-configmap.yml

2.3 创建 PV

暂时使用本地文件系统,可换成 Ceph 等

# 1. 所有节点上,挂载相应的存储盘或路径
$ mkdir -p /data/tdengine

# 2. 创建PV
$ cat > taos-pv.yml <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
  name: taos-pv
  namespace: taos-cluster
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: taos-storage
  local:
    path: /data/tdengine
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - k8s-master
          - k8s-node01
          - k8s-node02
EOF

$ kubectl apply -f taos-pv.yml

2.4 创建 PVC

$ cat > taos-pvc.yml <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: taos-pvc
  namespace: taos-cluster
spec:
  storageClassName: taos-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
EOF

$ kubectl apply -f taos-pvc.yml

2.5 创建 Service (无头服务)

$ cat > taos-headless.yml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: taosd
  namespace: taos-cluster
  labels:
    app: tdengine
spec:
  clusterIP: None
  ports:
  - name: tcp6030
    protocol: "TCP"
    port: 6030
  - name: tcp6035
    protocol: "TCP"
    port: 6035
  - name: tcp6041
    protocol: "TCP"
    port: 6041
  - name: udp6030
    protocol: "UDP"
    port: 6030
  - name: udp6031
    protocol: "UDP"
    port: 6031
  - name: udp6032
    protocol: "UDP"
    port: 6032
  - name: udp6033
    protocol: "UDP"
    port: 6033
  - name: udp6034
    protocol: "UDP"
    port: 6034
  - name: udp6035
    protocol: "UDP"
    port: 6035
  - name: udp6036
    protocol: "UDP"
    port: 6036
  - name: udp6037
    protocol: "UDP"
    port: 6037
  - name: udp6038
    protocol: "UDP"
    port: 6038
  - name: udp6039
    protocol: "UDP"
    port: 6039
  - name: udp6040
    protocol: "UDP"
    port: 6040
  selector:
    app: tdengine
EOF

$ kubectl apply -f  taos-headless.yml 

2.6 创建 StatefulSet

$ cat > taos-app.yml <<EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: "tdengine"
  namespace: taos-cluster
  labels:
    app: "tdengine"
spec:
  serviceName: "taosd"
  replicas: 3
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: "tdengine"
  template:
    metadata:
      name: "tdengine"
      labels:
        app: "tdengine"
    spec:
      volumes:
      - name: taos-storage
        persistentVolumeClaim:
          claimName: taos-pvc
      containers:
      - name: "tdengine"
        image: "tdengine-server:2.4.0.0"
        envFrom:
        - configMapRef:
            name: taos-cfg
        ports:
        - name: tcp6030
          protocol: "TCP"
          containerPort: 6030
        - name: tcp6035
          protocol: "TCP"
          containerPort: 6035
        - name: tcp6041
          protocol: "TCP"
          containerPort: 6041
        - name: udp6030
          protocol: "UDP"
          containerPort: 6030
        - name: udp6031
          protocol: "UDP"
          containerPort: 6031
        - name: udp6032
          protocol: "UDP"
          containerPort: 6032
        - name: udp6033
          protocol: "UDP"
          containerPort: 6033
        - name: udp6034
          protocol: "UDP"
          containerPort: 6034
        - name: udp6035
          protocol: "UDP"
          containerPort: 6035
        - name: udp6036
          protocol: "UDP"
          containerPort: 6036
        - name: udp6037
          protocol: "UDP"
          containerPort: 6037
        - name: udp6038
          protocol: "UDP"
          containerPort: 6038
        - name: udp6039
          protocol: "UDP"
          containerPort: 6039
        - name: udp6040
          protocol: "UDP"
          containerPort: 6040
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: SERVICE_NAME
          value: "taosd"
        - name: STS_NAME
          value: "tdengine"
        - name: STS_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: TZ
          value: "Asia/Shanghai"
        # TAOS_ prefix will configured in taos.cfg, strip prefix and camelCase.
        - name: TAOS_SERVER_PORT
          value: "6030"
        # Must set if you want a cluster.
        - name: TAOS_FIRST_EP
          value: "\$(STS_NAME)-0.\$(SERVICE_NAME).\$(STS_NAMESPACE).svc.cluster.local:\$(TAOS_SERVER_PORT)"
        # TAOS_FQND should always be setted in k8s env.
        - name: TAOS_FQDN
          value: "\$(POD_NAME).\$(SERVICE_NAME).\$(STS_NAMESPACE).svc.cluster.local"
        volumeMounts:
        - name: taos-storage
          mountPath: /var/lib/taos
        readinessProbe:
          exec:
            command:
            - taos
            - -s
            - "show mnodes"
          initialDelaySeconds: 5
          timeoutSeconds: 5000
        livenessProbe:
          tcpSocket:
            port: 6030
          initialDelaySeconds: 15
          periodSeconds: 20    
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: "Exists"
        effect: "NoSchedule"
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - tdengine
              topologyKey: kubernetes.io/hostname    
EOF

$ kubectl apply -f  taos-app.yml 

2.7 创建 Service (外部访问)

cat > taos-external-svc.yml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: taosd-np
  namespace: taos-cluster
  labels:
    app: tdengine
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
  type: NodePort
  selector:
    app: tdengine
  ports:
  - name: tcp6030
    protocol: "TCP"
    port: 6030
    targetPort: 6030
    nodePort: 36030
  - name: tcp6035
    protocol: "TCP"
    port: 6035
    targetPort: 6035
    nodePort: 36035
  - name: tcp6041
    protocol: "TCP"
    port: 6041
    targetPort: 6041
    nodePort: 36041
EOF

3. 验证

3.1 kubectl

登录到容器中,执行命令检查集群状态

$ kubectl exec -it tdengine-0 -n taos-cluster -- taos -s "show dnodes;"

Welcome to the TDengine shell from Linux, Client Version:2.2.2.0
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.

taos> show dnodes;
   id   |           end_point            | vnodes | cores  |   status   | role  |       create_time       |      offline reason      |
======================================================================================================================================
      1 | tdengine-0.taosd.taos-clust... |      0 |      2 | ready      | any   | 2021-11-26 02:42:25.932 |                          |
      2 | tdengine-1.taosd.taos-clust... |      1 |      2 | ready      | any   | 2021-11-26 02:42:35.633 |                          |
      3 | tdengine-2.taosd.taos-clust... |      1 |      2 | ready      | any   | 2021-11-26 02:42:48.004 |                          |
Query OK, 3 row(s) in set (0.001099s)

3.2 restful

容器外部,使用restful接口访问,注意:容器外,无法之间使用taos客户端连接

$ curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'show databases;' 192.168.80.240:36041/rest/sql
{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[["log","2021-11-26 02:42:26.936",6,1,1,1,10,"30",1,3,100,4096,1,3000,2,0,"us",0,"ready"],["iec61850","2021-12-01 01:13:56.176",59,1,1,1,10,"365",16,6,100,4096,1,3000,2,0,"ms",0,"ready"]],"rows":2}

$ curl -u root:taosdata -d 'show databases;' 192.168.80.240:36041/rest/sql

参考资料:

https://github.com/taosdata/TDengine-Operator 【官方 kubernetes 安装tdengine 方案】

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TDEngine 集群安装 (K8S) 的相关文章

  • 十六、K8s安全管理与资源限制

    实验环境 按照图示部署好了K8s集群 一个Master 两个worker nodes 访问控制概述 apiserver作为k8s集群系统的网关 是访问及管理资源对象的唯一入口 余下所有需要访问集群资源的组件 包括kube controlle
  • K8S 工作负载(一)

    K8S 工作负载 1 Pod Pod 是 Kubernetes 中创建 管理和调度的最小计算单元 用户可以在 K8S 中通过调用 Pod API生成一个 Pod 让 K8S 对其进行调度 Pod 是一组 一个或多个 容器 这些容器共享存储
  • underlay和overlay? & 传统网络和数据中心网络 ?

    underlay和overlay 百度 Underlay 和 Overlay 是网络架构中两个常用的概念 用于描述不同层次或视角下的网络结构和通信方式 1 Underlay 底层网络 Underlay 是指基础网络层 即物理网络或基础网络架
  • minikube单机安装nfs服务

    1 安装 nfs server sudo apt get update sudo apt get install y nfs kernel server 2 创建目录 配置 IP 共享目录绑定 vim etc exports 新增 data
  • k8s Pod定义yaml配置文件详解

    此文件相关配置查询 此文件只做参考 以查询为准 kubectl explain 为文档查询命令如 kubectl explain pod spec volumes apiVersion v1 版本 kind pod 类型 pod metad
  • Rancher 全球化部署最佳实践

    作者 万绍远 CNCF 基金会官方认证 Kubernetes CKA CKS 工程师 云原生解决方案架构师 对 ceph Openstack Kubernetes prometheus 技术和其他云原生相关技术有较深入的研究 参与设计并实施
  • CentOS 7 下 minikube 部署 && 配置

    CentOS 7 下 minikube 部署 配置 文章目录 CentOS 7 下 minikube 部署 配置 下载 安装 下载安装脚本 安装 minikube 启动 minikube 环境 安装 kubectl 工具 启动 miniku
  • 如何解决K8S节点显示NotReady

    文章目录 kubernetes节点断电重启 kubernetes节点断电重启 背景 运行的好好的k8s集群 某天断电 发现一个节点炸了 显示NotReady kubectl get nodes 那么如何查找问题呢 我们用它 journalc
  • Kubernetes 集群部署 ------ 二进制部署(二)

    单节点 https blog csdn net Yplayer001 article details 104234807 先具备单master1节点部署环境 三 master02部署 优先关闭防火墙和selinux服务 在master01上
  • Rancher 图形化管理K8S

    题外话 之前我们一直都是使用命令行来管理K8S的 这种做法虽然对程序员来说看起来很炫酷 但有时候用起来还是挺麻烦的 今天我们来介绍一个K8S可视化管理工具Rancher 使用它可以大大减少我们管理K8S的工作量 希望对大家有所帮助 简介 R
  • kubectl常用命令

    alias k kubectl alias kc k create f alias kgp k get pods alias kdp k describe pods alias kdep k delete pods alias kl k l
  • kubeadm配置虚拟机k8s集群

    环境 centos7 vm pro windows terminal termius 虚拟机 硬件配置 2核2G 实验用 具体可根据电脑调整 配置3台 master01 node01 node02 通过克隆虚拟机直接复制 配置通一项以后建议
  • k8s基础5——Pod常用命令、资源共享机制、重启策略和健康检查、环境变量、初始化容器、静态pod

    文章目录 一 基本了解 二 管理命令 三 yaml文件参数大全 四 创建pod的工作流程 五 资源共享机制 5 1 共享网络 5 2 共享存储 六 生命周期 重启策略 健康检查 七 环境变量 八 Init Containe初始化容器 九 静
  • k8s问题 CrashLoopBackOff

    我们创建资源发现资源出现CrashLoopBackOff解决 CrashLoopBackOff 告诉我们 Kubernetes 正在尽力启动这个 Pod 但是一个或多个容器已经挂了 或者正被删除 root localhost kubectl
  • Kubernets原理分解

    主节点 master 快速介绍 master也要装kubelet和kubeproxy 前端访问 UI CLI kube apiserver scheduler controller manager etcd kubelet kubeprox
  • kubernetes报错Error from server (AlreadyExists): error when creating "kubernetes-dashboard.yaml": serv

    在执行 kubectl apply f kubernetes dashboard yaml 报错 Error from server AlreadyExists error when creating kubernetes dashboar
  • k8s学习(五)ReplicaSet的使用

    ReplicaSet ReplicaSet 的目的是维护一组在任何时候都处于运行状态的 Pod 副本的稳定集合 可确保指定数量的pod在任何设定的时间运行 因此 它通常用来保证给定数量的 完全相同的 Pod 的可用性 示例 1 nginx
  • 国内k8s集群部署的几种方式

    前言 总所周知 由于某种原因 通过官方的方式在国内是无法顺利部署k8s集群的 这里记录下在国内部署的几种方式 部署方式 目前我所了解有以下几种方式 使用kubeadmin通过离线镜像的方式 网上教程和镜像包挺多的 通过厂商集成的方式如 ra
  • k8s部署Prometheus抓取pods的metrics

    1 暴露pods给Prometheus抓取 spec replicas app replicas template metadata annotations prometheus io scrape true prometheus io p
  • TDengine数据库-TAOS涛思数据-批量下载上亿大数据成csv 解决bug: Query interrupted (Query terminated) 4798749 row(s) in set

    目录 前言 taos shell命令批量下载数据库遇到中断问题 分析问题 解决方案 查看tao cfg文件 使用分页下载 在合并csv 1 构建 sql文件批量进行下载 2 合并分csv文件成总csv文件 总结 其它资料下载 前言 TDen

随机推荐