部署

可执行文件部署

dtm 目前已支持brew直接安装,暂未支持apt/yum等方式直接安装,您可以从github上面下载相应版本,或者通过go环境,编译出相关的二进制文件。

编译

您需要有go 1.16以上的环境,通过下面命令编译出二进制文件

  1. go build

配置

您可以设置相关的环境变量(参见部署基础),也可以在工作目录下,参考配置样板文件创建conf.yml文件

启动

dtm会监听

  • HTTP: 36789
  • gRPC: 36790
  1. ./dtm -c ./conf.yml

Docker部署

Docker启动

  1. docker run --name dtm -p 36789:36789 -p 36790:36790 -e STORE_DRIVER=mysql -e STORE_HOST=localhost -e STORE_USER=root -e STORE_PASSWORD= -e STORE_PORT=3306 yedf/dtm:latest

各个参数,详见部署基础

docker-compose启动

示例 docker-compose.yaml 文件:

  1. version: '3'
  2. services:
  3. dtm:
  4. image: yedf/dtm
  5. environment:
  6. STORE_DRIVER: mysql
  7. STORE_HOST: localhost
  8. STORE_USER: root
  9. STORE_PASSWORD: ''
  10. STORE_PORT: 3306
  11. ports:
  12. - '36789:36789'
  13. - '36790:36790'

容器其他命令

交互式使用dtm容器

docker exec -it dtm sh

查看日志

docker logs -f dtm

Kubernetes部署

当前dtm支持http协议,可以把前面docker部署的方式,增加K8S的deployment配置,完成K8S部署,下面给出一个deployment.yml的一个参考

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: dtm
  5. labels:
  6. app: dtm
  7. spec:
  8. replicas: 2
  9. selector:
  10. matchLabels:
  11. app: dtm
  12. template:
  13. metadata:
  14. labels:
  15. app: dtm
  16. spec:
  17. containers:
  18. - name: dtm
  19. image: yedf/dtm:latest
  20. imagePullPolicy: IfNotPresent
  21. args:
  22. - "-c=/app/dtm/configs/config.yaml"
  23. volumeMounts:
  24. - mountPath: /app/dtm/configs
  25. name: config
  26. ports:
  27. - containerPort: 36789
  28. protocol: TCP
  29. name: http
  30. - containerPort: 36790
  31. protocol: TCP
  32. name: grpc
  33. livenessProbe:
  34. httpGet:
  35. path: /api/ping
  36. port: 36789
  37. scheme: HTTP
  38. readinessProbe:
  39. httpGet:
  40. path: /api/ping
  41. port: 36789
  42. scheme: HTTP
  43. resources:
  44. requests:
  45. cpu: 200m
  46. memory: 200Mi
  47. volumes:
  48. - name: config
  49. configMap:
  50. name: dtm-conf
  51. ---
  52. apiVersion: v1
  53. kind: ConfigMap
  54. metadata:
  55. name: dtm-conf
  56. labels:
  57. app: dtm
  58. data:
  59. config.yaml: |-
  60. Store:
  61. Driver: mysql # 此处以 mysql 为例,其他数据库可自行替换
  62. Host: dtm-db # 此处设置为集群外部的数据库 host,或者集群内部的数据库 svc-dns
  63. Port: 3306
  64. User: root
  65. Password: ''
  66. ---
  67. apiVersion: v1
  68. kind: Service
  69. metadata:
  70. name: dtm-svc
  71. labels:
  72. app: dtm
  73. spec:
  74. ports:
  75. - port: 36790
  76. targetPort: 36790
  77. name: grpc
  78. appProtocol: grpc # Kubernetes v1.20 [stable],低版本请剔除此行
  79. - port: 36789
  80. targetPort: 36789
  81. name: http
  82. appProtocol: http # Kubernetes v1.20 [stable],低版本请剔除此行
  83. selector:
  84. app: dtm
  85. type: ClusterIP
  86. ---
  87. apiVersion: networking.k8s.io/v1
  88. kind: Ingress
  89. metadata:
  90. name: dtm-ing
  91. spec:
  92. rules:
  93. - host: "your-domain.com"
  94. http:
  95. paths:
  96. - path: /
  97. pathType: Prefix
  98. backend:
  99. service:
  100. name: dtm-svc
  101. port:
  102. number: 36789 # 此处为 http server,grpc server 的设置,请访问 https://kubernetes.github.io/ingress-nginx/examples/grpc/
  103. ingressClassName: nginx # 使用了其他的 ingressClassName, 请自行查询

Helm部署

使用

安装 DTM chart:

  1. helm install --create-namespace -n dtm-system dtm ./charts

升级 DTM chart:

  1. helm upgrade -n dtm-system dtm ./charts

拆卸 DTM chart:

  1. helm delete -n dtm-system dtm

参数

Configuration 参数

Key Description Value
configuration DTM 配置. 为 DTM 生成 config.yaml, 参考: sample config ""

Autoscaling 参数

Name Description Value
autoscaling.enabled 为 DTM 启用 pods 弹性伸缩 false
autoscaling.minReplicas DTM 副本的最小数量 1
autoscaling.maxReplicas DTM 副本的最大数量 10
autoscaling.targetCPUUtilizationPercentage 目标cpu使用率 80
autoscaling.targetMemoryUtilizationPercentage 目标内存使用率 80

Ingress 参数

Key Description Value
ingress.enabled 为 DTM 启用 ingress false
ingress.className 为 Ingress 指定一个 Ingress class。 (Kubernetes 1.18+) "nginx"
ingress.annotations 配置 TLS 证书的自动签发注解等. {}
ingress.hosts.host 为 DTM 指定主机名. "your-domain.com"
ingress.hosts.paths.path 为 DTM 配置匹配路径 "/"
ingress.hosts.paths.pathType Ingress 匹配类型, PrefixExact "Prefix"
ingress.tls 为 DTM 主机名配置 TLS secret []