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: v1.20.0-lts
  16. imagePullPolicy: Always
  17. mysql: # 数据库相关配置
  18. host: metersphere-mysql
  19. port: 3306
  20. username: root
  21. password: Password123@mysql
  22. redis: # Redis相关配置
  23. host: metersphere-redis
  24. port: 6379
  25. password: Password123@redis
  26. database: 1
  27. kafka: # Kafka相关配置
  28. host: metersphere-kafka
  29. port: 9092
  30. metricTopic: JMETER_METRICS
  31. logTopic: JMETER_LOGS
  32. testTopic: LOAD_TESTS
  33. reportTopic: JMETER_REPORTS
  34. server:
  35. enabled: true
  36. image: metersphere
  37. replicas: 1
  38. properties: |-
  39. ## DATABASE
  40. spring.datasource.url=jdbc:mysql://{{.Values.common.mysql.host}}:{{.Values.common.mysql.port}}/metersphere?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
  41. spring.datasource.username={{.Values.common.mysql.username}}
  42. spring.datasource.password={{.Values.common.mysql.password}}
  43. ## redis
  44. spring.session.store-type=redis
  45. spring.redis.host={{.Values.common.redis.host}}
  46. spring.redis.port={{.Values.common.redis.port}}
  47. spring.redis.database={{.Values.common.redis.database}}
  48. spring.redis.password={{.Values.common.redis.password}}
  49. ## KAFKA
  50. kafka.partitions=1
  51. kafka.replicas=1
  52. kafka.topic={{.Values.common.kafka.metricTopic}}
  53. kafka.bootstrap-servers={{.Values.common.kafka.host}}.{{.Release.Namespace}}:{{.Values.common.kafka.port}}
  54. kafka.log.topic={{.Values.common.kafka.logTopic}}
  55. kafka.test.topic={{.Values.common.kafka.testTopic}}
  56. kafka.report.topic={{.Values.common.kafka.reportTopic}}
  57. tcp.mock.port=10000
  58. ## JMETER
  59. jmeter.image={{ .Values.common.imagePrefix }}{{.Values.jmeter.image}}:{{.Values.jmeter.imageTag}}
  60. jmeter.pod.threads.limit=500
  61. ## K8S
  62. k8s.node-controller-image={{ .Values.common.imagePrefix }}{{.Values.nodeController.image}}:{{.Values.common.imageTag}}
  63. logger.sql.level=info
  64. dataStreaming:
  65. enabled: true
  66. image: ms-data-streaming
  67. replicas: 1
  68. properties: |-
  69. ## DATABASE
  70. spring.datasource.url=jdbc:mysql://{{.Values.common.mysql.host}}:{{.Values.common.mysql.port}}/metersphere?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false
  71. spring.datasource.username={{.Values.common.mysql.username}}
  72. spring.datasource.password={{.Values.common.mysql.password}}
  73. ## KAFKA
  74. kafka.partitions=1
  75. kafka.replicas=1
  76. kafka.topic={{.Values.common.kafka.metricTopic}}
  77. kafka.bootstrap-servers={{.Values.common.kafka.host}}:{{.Values.common.kafka.port}}
  78. kafka.log.topic={{.Values.common.kafka.logTopic}}
  79. kafka.test.topic={{.Values.common.kafka.testTopic}}
  80. kafka.report.topic={{.Values.common.kafka.reportTopic}}
  81. jmeter.report.granularity=5000
  82. nodeController:
  83. enabled: true
  84. image: ms-node-controller
  85. replicas: 1
  86. properties: |-
  87. ## TBD
  88. jmeter:
  89. image: jmeter-master
  90. imageTag: 5.4.3-ms5-jdk11
  91. logPersistence:
  92. enabled: false
  93. accessModes: ReadWriteOnce
  94. size: 10Gi
  95. dataPersistence:
  96. enabled: true
  97. accessModes: ReadWriteOnce
  98. size: 10Gi
  99. mysql:
  100. enabled: true # 引用外部数据库时,可以修改为false,启动时不再安装mysql
  101. image: mysql
  102. imageTag: "5.7.25"
  103. password: Password123@mysql
  104. persistence:
  105. enabled: true
  106. accessModes: ReadWriteOnce
  107. size: 20Gi
  108. redis:
  109. enabled: true # 引用外部redis时,可以修改为false,启动时不再安装redis
  110. image: redis
  111. imageTag: "6.2.6"
  112. password: Password123@redis
  113. persistence:
  114. enabled: true
  115. accessModes: ReadWriteOnce
  116. size: 10Gi
  117. kafka:
  118. enabled: true # 引用外部kafka时,可以修改为false,启动时不再安装kafka
  119. image:
  120. registry: registry.cn-qingdao.aliyuncs.com/metersphere
  121. repository: kafka
  122. tag: 2.8.1
  123. fullnameOverride: metersphere-kafka
  124. persistence:
  125. enabled: false
  126. logPersistence:
  127. enabled: false
  128. logFlushIntervalMessages: _10000
  129. logFlushIntervalMs: 1000
  130. logRetentionBytes: _1073741824
  131. logRetentionCheckIntervalMs: 300000
  132. logRetentionHours: 168
  133. logSegmentBytes: _1073741824
  134. maxMessageBytes: _1000012
  135. livenessProbe:
  136. initialDelaySeconds: 20
  137. periodSeconds: 15
  138. timeoutSeconds: 15
  139. readinessProbe:
  140. initialDelaySeconds: 20
  141. periodSeconds: 15
  142. timeoutSeconds: 15
  143. externalAccess:
  144. enabled: true
  145. service:
  146. type: NodePort
  147. useHostIPs: true
  148. autoDiscovery:
  149. enabled: true
  150. serviceAccount:
  151. create: true
  152. rbac:
  153. create: true
  154. zookeeper:
  155. enabled: true
  156. logLevel: ERROR
  157. persistence:
  158. enabled: false
  159. fullnameOverride: metersphere-zookeeper
  160. image:
  161. registry: registry.cn-qingdao.aliyuncs.com/metersphere
  162. repository: zookeeper
  163. tag: 3.7.0
  164. extraEnvVars:
  165. - name: FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS
  166. value: "true"
  167. zookeeper: # 引用外部kafka时,可以修改为false,启动时不再安装zookeeper
  168. 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 的访问方式

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

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

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