Kubernetes 中部署

Helm Charts 方式部署 MeterSphere

Helm Charts 在线部署

  1. kubectl create ns ms
  2. helm repo add bitnami https://charts.bitnami.com/bitnami
  3. helm repo add metersphere https://metersphere.github.io/helm-chart/
  4. # 从 chart 仓库中更新本地可用chart的信息
  5. helm repo update
  6. helm install metersphere metersphere/metersphere -n ms

Helm Charts 离线部署

1.导入镜像

下载 MeterSphere 最新版本的离线安装包并且解压,将安装包里 image 目录下的镜像tar包上传到kubernetes的镜像库里或者手动load到kubernetes各个宿主机节点上。

MeterSphere 离线安装包下载链接: https://community.fit2cloud.com/#/products/metersphere/downloads

2.下载离线 Chart 包

helm-chart 安装包下载链接: https://github.com/metersphere/helm-chart/releases

如:https://github.com/metersphere/helm-chart/releases/download/metersphere-1.1.0/metersphere-1.1.0.tgz

3.安装

  1. helm install metersphere metersphere-1.0.10.tgz -n ms

Helm Charts 在线升级

  1. helm repo update # 从 chart 仓库中更新本地可用chart的信息
  2. helm upgrade metersphere metersphere/metersphere -n ms

Helm Charts 离线升级

1.导入新版本镜像

下载 MeterSphere 最新版本的离线安装包并且解压,将安装包里 image 目录下的镜像tar包上传到kubernetes的镜像库里或者手动 load 到 kubernetes 各个宿主机节点上。

MeterSphere 离线安装包下载链接: https://community.fit2cloud.com/#/products/metersphere/downloads

2.下载最新离线 Chart 包

helm-chart 安装包下载链接: https://github.com/metersphere/helm-chart/releases

如:https://github.com/metersphere/helm-chart/releases/download/metersphere-1.1.0/metersphere-1.1.0.tgz

3.升级

  1. helm upgrade metersphere metersphere-1.0.10.tgz -n ms

values.yaml

  1. ingress: # 不使用 ingress 可以关闭
  2. enabled: true
  3. host: ms-dev.apps.metersphere.com
  4. annotations: {}
  5. ## example for ingress annotions.
  6. # kubernetes.io/ingress.class: nginx
  7. # kubernetes.io/tls-acme: "true"
  8. https:
  9. enabled: false
  10. secretName: ""
  11. common:
  12. imagePrefix: "registry.cn-qingdao.aliyuncs.com/metersphere/"
  13. imagePullSecrets: nil
  14. storageClass: default
  15. imageTag: v2.3.0 # 安装的版本号
  16. imagePullPolicy: Always # 镜像拉取策略
  17. properties: |-
  18. ## DATABASE
  19. spring.datasource.url=jdbc:mysql://{{.Values.mysql.host}}:{{.Values.mysql.port}}/metersphere?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
  20. spring.datasource.username={{.Values.mysql.username}}
  21. spring.datasource.password={{.Values.mysql.password}}
  22. ## redis
  23. spring.session.store-type=redis
  24. spring.redis.host={{.Values.redis.host}}
  25. spring.redis.port={{.Values.redis.port}}
  26. spring.redis.database={{.Values.redis.database}}
  27. spring.redis.password={{.Values.redis.password}}
  28. ## KAFKA
  29. kafka.partitions=1
  30. kafka.replicas=1
  31. kafka.topic={{.Values.kafka.metricTopic}}
  32. kafka.bootstrap-servers={{.Values.kafka.host}}.{{.Release.Namespace}}:{{.Values.kafka.port}}
  33. kafka.log.topic={{.Values.kafka.logTopic}}
  34. kafka.test.topic={{.Values.kafka.testTopic}}
  35. kafka.report.topic={{.Values.kafka.reportTopic}}
  36. tcp.mock.port=10000
  37. ## minio
  38. minio.endpoint=http://{{.Values.minio.host}}:{{.Values.minio.port}}
  39. minio.access-key={{.Values.minio.username}}
  40. minio.secret-key={{.Values.minio.password}}
  41. ## JMETER
  42. jmeter.image={{ .Values.common.imagePrefix }}{{.Values.jmeter.image}}:{{.Values.jmeter.imageTag}}
  43. jmeter.pod.threads.limit=500
  44. ## K8S
  45. k8s.node-controller-image={{ .Values.common.imagePrefix }}{{.Values.nodeController.image}}:{{.Values.common.imageTag}}
  46. ## spring cloud
  47. eureka.client.service-url.defaultZone=http://{{.Values.eureka.host}}:{{.Values.eureka.port}}/eureka/
  48. logger.sql.level=info
  49. apiTest: # 接口测试模块,可以修改为false,启动时不再安装接口测试模块
  50. enabled: true
  51. image: api-test
  52. replicas: 1
  53. performanceTest: # 性能测试模块,可以修改为false,启动时不再安装性能测试模块
  54. enabled: true
  55. image: performance-test
  56. replicas: 1
  57. systemSetting: # 系统设置模块,可以修改为false,启动时不再安装系统设置模块
  58. enabled: true
  59. image: system-setting
  60. replicas: 1
  61. projectManagement: # 项目管理模块,可以修改为false,启动时不再安装项目管理模块
  62. enabled: true
  63. image: project-management
  64. replicas: 1
  65. reportStat: # 报告管理模块,可以修改为false,启动时不再安装报告管理模块
  66. enabled: true
  67. image: report-stat
  68. replicas: 1
  69. testTrack: # 测试跟踪模块,可以修改为false,启动时不再安装测试跟踪模块
  70. enabled: true
  71. image: test-track
  72. replicas: 1
  73. gateway: # 网关,可以修改为false,启动时不再安装
  74. enabled: true
  75. image: gateway
  76. replicas: 1
  77. eureka: # 服务注册中心,可以修改为false,启动时不再安装
  78. enabled: true
  79. image: eureka
  80. host: metersphere-eureka
  81. port: 8761
  82. replicas: 1
  83. dataStreaming:
  84. enabled: true
  85. image: data-streaming
  86. replicas: 1
  87. properties: |-
  88. ## DATABASE
  89. spring.datasource.url=jdbc:mysql://{{.Values.mysql.host}}:{{.Values.mysql.port}}/metersphere?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
  90. spring.datasource.username={{.Values.mysql.username}}
  91. spring.datasource.password={{.Values.mysql.password}}
  92. ## KAFKA
  93. kafka.partitions=1
  94. kafka.replicas=1
  95. kafka.topic={{.Values.kafka.metricTopic}}
  96. kafka.bootstrap-servers={{.Values.kafka.host}}:{{.Values.kafka.port}}
  97. kafka.log.topic={{.Values.kafka.logTopic}}
  98. kafka.test.topic={{.Values.kafka.testTopic}}
  99. kafka.report.topic={{.Values.kafka.reportTopic}}
  100. jmeter.report.granularity=5000
  101. ## minio
  102. minio.endpoint=http://{{.Values.minio.host}}:{{.Values.minio.port}}
  103. minio.access-key={{.Values.minio.username}}
  104. minio.secret-key={{.Values.minio.password}}
  105. nodeController:
  106. enabled: true
  107. image: node-controller
  108. replicas: 1
  109. properties: |-
  110. ## TBD
  111. jmeter:
  112. image: jmeter-master
  113. imageTag: 5.4.3-ms5-jdk11
  114. logPersistence:
  115. enabled: true
  116. accessModes: ReadWriteOnce
  117. size: 10Gi
  118. dataPersistence:
  119. enabled: true
  120. accessModes: ReadWriteOnce
  121. size: 10Gi
  122. mysql: # 引用外部数据库时,可以修改为false,启动时不再安装mysql
  123. enabled: true
  124. image: mysql
  125. imageTag: "8.0.30"
  126. host: metersphere-mysql
  127. port: 3306
  128. username: root
  129. password: Password123@mysql
  130. persistence:
  131. enabled: true
  132. accessModes: ReadWriteOnce
  133. size: 20Gi
  134. minio:
  135. enabled: true
  136. image: minio
  137. imageTag: "latest"
  138. username: admin
  139. password: Password123@minio
  140. host: metersphere-minio
  141. port: 9000
  142. persistence:
  143. enabled: true
  144. accessModes: ReadWriteOnce
  145. size: 20Gi
  146. redis: # 引用外部redis时,可以修改为false,启动时不再安装redis
  147. enabled: true
  148. image: redis
  149. imageTag: "6.2.6"
  150. password: Password123@redis
  151. host: metersphere-redis
  152. port: 6379
  153. database: 1
  154. persistence:
  155. enabled: true
  156. accessModes: ReadWriteOnce
  157. size: 10Gi
  158. kafka: # 引用外部kafka时,可以修改为false,启动时不再安装kafka
  159. enabled: true
  160. fullnameOverride: metersphere-kafka
  161. host: metersphere-kafka
  162. port: 9092
  163. metricTopic: JMETER_METRICS
  164. logTopic: JMETER_LOGS
  165. testTopic: LOAD_TESTS
  166. reportTopic: JMETER_REPORTS
  167. persistence:
  168. enabled: false
  169. logPersistence:
  170. enabled: false
  171. logFlushIntervalMessages: _10000
  172. logFlushIntervalMs: 1000
  173. logRetentionBytes: _1073741824
  174. logRetentionCheckIntervalMs: 300000
  175. logRetentionHours: 168
  176. logSegmentBytes: _1073741824
  177. maxMessageBytes: _1000012
  178. livenessProbe:
  179. initialDelaySeconds: 20
  180. periodSeconds: 15
  181. timeoutSeconds: 15
  182. readinessProbe:
  183. initialDelaySeconds: 20
  184. periodSeconds: 15
  185. timeoutSeconds: 15
  186. externalAccess:
  187. enabled: true
  188. service:
  189. type: NodePort
  190. useHostIPs: true
  191. autoDiscovery:
  192. enabled: true
  193. serviceAccount:
  194. create: true
  195. rbac:
  196. create: true
  197. zookeeper:
  198. enabled: true
  199. logLevel: ERROR
  200. persistence:
  201. enabled: false
  202. fullnameOverride: metersphere-zookeeper
  203. extraEnvVars:
  204. - name: FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS
  205. value: "true"
  206. zookeeper:
  207. enabled: true

若想控制数据库的连接数,请在 values.yml 的 DATABASE 处,新增如下两行参数

  1. spring.datasource.hikari.maximum-pool-size=你想要的数值
  2. spring.datasource.quartz.hikari.maximum-pool-size=你想要的数值

引用外部 Kafka

  1. vim values.yaml
  2. values.yaml zookeeper.enabled kafka.enabled 改为 false
  3. common.kafka.hostcommon.kafka.port 改为外部 kafka 的地址和端口

引用外部 MySQL

  1. vim values.yaml
  2. values.yaml mysql.enabled 改为 false
  3. common.host.hostcommon.host.portcommon.host.usernamecommon.host.password 改为外部 mysql 的地址、端口及用户名、密码

引用外部 Redis

  1. vim values.yaml
  2. values.yaml redis.enabled 改为 false
  3. common.redis.hostcommon.redis.portcommon.redis.password 改为外部 redis 的地址、端口和密码

创建一个 Node Port 的访问方式

注意

使用命令 kubectl get svc -n ms 可查看 metersphere-gateway 所占用的端口号。

如果不使用 ingress 的访问方式,可以创建一个 nodeport

  1. vi ms-gateway-nodeport.yaml
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: metersphere-gateway-nodeport
  6. namespace: ms
  7. spec:
  8. ports:
  9. - name: metersphere-gateway
  10. protocol: TCP
  11. port: 8000
  12. targetPort: 8000
  13. nodePort: 30801
  14. type: NodePort
  15. selector:
  16. app: metersphere-gateway
  17. kubectl create -f ms-gateway-nodeport.yaml

访问 MeterSphere 页面: http://nodeIP:30801