github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/apecloud-mysql/templates/clusterdefinition.yaml (about) 1 apiVersion: apps.kubeblocks.io/v1alpha1 2 kind: ClusterDefinition 3 metadata: 4 name: apecloud-mysql 5 labels: 6 {{- include "apecloud-mysql.labels" . | nindent 4 }} 7 spec: 8 type: mysql 9 connectionCredential: 10 username: root 11 password: "$(RANDOM_PASSWD)" 12 endpoint: "$(SVC_FQDN):$(SVC_PORT_mysql)" 13 host: "$(SVC_FQDN)" 14 port: "$(SVC_PORT_mysql)" 15 componentDefs: 16 - name: mysql 17 characterType: mysql 18 probes: 19 roleProbe: 20 failureThreshold: {{ .Values.roleProbe.failureThreshold }} 21 periodSeconds: {{ .Values.roleProbe.periodSeconds }} 22 timeoutSeconds: {{ .Values.roleProbe.timeoutSeconds }} 23 monitor: 24 builtIn: false 25 exporterConfig: 26 scrapePath: /metrics 27 scrapePort: {{ .Values.metrics.service.port }} 28 logConfigs: 29 {{- range $name,$pattern := .Values.logConfigs }} 30 - name: {{ $name }} 31 filePathPattern: {{ $pattern }} 32 {{- end }} 33 configSpecs: 34 - name: mysql-consensusset-config 35 templateRef: mysql8.0-config-template 36 constraintRef: mysql8.0-config-constraints 37 volumeName: mysql-config 38 namespace: {{ .Release.Namespace }} 39 - name: agamotto-configuration 40 templateRef: apecloud-mysql8-agamotto-configuration 41 namespace: {{ .Release.Namespace }} 42 volumeName: agamotto-configuration 43 # for only read, mysql container switched user account. 44 defaultMode: 0444 45 - name: vttablet-config 46 templateRef: vttablet-config-template 47 constraintRef: mysql-scale-vttablet-config-constraints 48 volumeName: mysql-scale-config 49 namespace: {{ .Release.Namespace }} 50 scriptSpecs: 51 - name: apecloud-mysql-scripts 52 templateRef: apecloud-mysql-scripts 53 namespace: {{ .Release.Namespace }} 54 volumeName: scripts 55 # for read and execute, mysql container switched user account. 56 defaultMode: 0555 57 workloadType: Consensus 58 consensusSpec: 59 leader: 60 name: leader 61 accessMode: ReadWrite 62 followers: 63 - name: follower 64 accessMode: Readonly 65 learner: 66 name: learner 67 accessMode: Readonly 68 service: 69 ports: 70 - name: mysql 71 port: 3306 72 targetPort: mysql 73 horizontalScalePolicy: 74 type: CloneVolume 75 backupPolicyTemplateName: apecloud-mysql-backup-policy-for-hscale 76 switchoverSpec: 77 withCandidate: 78 cmdExecutorConfig: 79 image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ default .Values.image.tag }} 80 command: 81 - /scripts/switchover-with-candidate.sh 82 scriptSpecSelectors: 83 - name: apecloud-mysql-scripts 84 withoutCandidate: 85 cmdExecutorConfig: 86 image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ default .Values.image.tag }} 87 command: 88 - /scripts/switchover-without-candidate.sh 89 scriptSpecSelectors: 90 - name: apecloud-mysql-scripts 91 volumeTypes: 92 - name: data 93 type: data 94 podSpec: 95 containers: 96 - name: mysql 97 volumeMounts: 98 - mountPath: {{ .Values.mysqlConfigs.dataMountPath }} 99 name: data 100 - mountPath: /opt/mysql 101 name: mysql-config 102 - name: scripts 103 mountPath: /scripts 104 - name: annotations 105 mountPath: /etc/annotations 106 ports: 107 - containerPort: 3306 108 name: mysql 109 - containerPort: 13306 110 name: paxos 111 env: 112 - name: SERVICE_PORT 113 value: "3306" 114 - name: MYSQL_ROOT_HOST 115 value: {{ .Values.auth.rootHost | default "%" | quote }} 116 - name: MYSQL_ROOT_USER 117 valueFrom: 118 secretKeyRef: 119 name: $(CONN_CREDENTIAL_SECRET_NAME) 120 key: username 121 optional: false 122 - name: MYSQL_ROOT_PASSWORD 123 valueFrom: 124 secretKeyRef: 125 name: $(CONN_CREDENTIAL_SECRET_NAME) 126 key: password 127 optional: false 128 - name: MYSQL_DATABASE 129 value: {{- if .Values.auth.createDatabase }} {{ .Values.auth.database | quote }} {{- else }} "" {{- end }} 130 - name: MYSQL_USER 131 value: {{ .Values.auth.username | default "" | quote }} 132 - name: MYSQL_PASSWORD 133 value: {{ .Values.auth.password | default "" | quote }} 134 - name: CLUSTER_ID 135 value: {{ .Values.cluster.clusterId | default "1" | quote }} 136 - name: CLUSTER_START_INDEX 137 value: {{ .Values.cluster.clusterStartIndex | default "1" | quote }} 138 - name: REPLICATION_USER 139 value: {{ .Values.auth.replicationUser | default "replicator" | quote }} 140 - name: REPLICATION_PASSWORD 141 value: {{ .Values.auth.replicationPassword | default "" | quote }} 142 - name: MYSQL_TEMPLATE_CONFIG 143 value: {{ if .Values.cluster.templateConfig }}{{ .Values.cluster.templateConfig }}{{ end }} 144 - name: MYSQL_CUSTOM_CONFIG 145 value: {{ if .Values.cluster.customConfig }}{{ .Values.cluster.customConfig }}{{ end }} 146 - name: MYSQL_DYNAMIC_CONFIG 147 value: {{ if .Values.cluster.dynamicConfig }}{{ .Values.cluster.dynamicConfig }}{{ end }} 148 - name: KB_EMBEDDED_WESQL 149 value: {{ .Values.cluster.kbWeSQLImage | default "1" | quote }} 150 # - name: KB_MYSQL_LEADER 151 # valueFrom: 152 # configMapKeyRef: 153 # name: $(COMP_ENV_CM_NAME) 154 # key: KB_LEADER 155 # optional: false 156 # - name: KB_MYSQL_FOLLOWERS 157 # valueFrom: 158 # configMapKeyRef: 159 # name: $(COMP_ENV_CM_NAME) 160 # key: KB_FOLLOWERS 161 # optional: false 162 # - name: KB_MYSQL_N 163 # valueFrom: 164 # configMapKeyRef: 165 # name: $(COMP_ENV_CM_NAME) 166 # key: KB_REPLICA_COUNT 167 # optional: false 168 # - name: KB_MYSQL_CLUSTER_UID 169 # valueFrom: 170 # configMapKeyRef: 171 # name: $(COMP_ENV_CM_NAME) 172 # key: KB_CLUSTER_UID 173 # optional: false 174 175 command: ["/scripts/setup.sh"] 176 lifecycle: 177 preStop: 178 exec: 179 command: ["/scripts/pre-stop.sh"] 180 - name: metrics 181 securityContext: 182 runAsNonRoot: false 183 runAsUser: 0 184 env: 185 - name: DB_TYPE 186 value: MySQL 187 - name: ENDPOINT 188 value: {{ printf "localhost:3306" }} 189 - name: MYSQL_USER 190 valueFrom: 191 secretKeyRef: 192 name: $(CONN_CREDENTIAL_SECRET_NAME) 193 key: username 194 optional: false 195 - name: MYSQL_PASSWORD 196 valueFrom: 197 secretKeyRef: 198 name: $(CONN_CREDENTIAL_SECRET_NAME) 199 key: password 200 optional: false 201 command: ["/scripts/agamotto.sh"] 202 ports: 203 - name: http-metrics 204 containerPort: {{ .Values.metrics.service.port }} 205 volumeMounts: 206 - name: agamotto-configuration 207 mountPath: /opt/agamotto 208 - name: data 209 mountPath: {{ .Values.mysqlConfigs.dataMountPath }} 210 {{- if .Values.logCollector.enabled }} 211 - name: log-data 212 mountPath: /var/log/kubeblocks 213 readOnly: false 214 {{- end }} 215 - name: scripts 216 mountPath: /scripts 217 - name: vttablet 218 ports: 219 - containerPort: 15100 220 name: vttabletport 221 - containerPort: 16100 222 name: vttabletgrpc 223 env: 224 - name: CELL 225 value: {{ .Values.wesqlscale.cell | default "zone1" | quote }} 226 - name: ETCD_SERVER 227 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 228 - name: ETCD_PORT 229 value: "2379" 230 - name: TOPOLOGY_FLAGS 231 value: "--topo_implementation etcd2 --topo_global_server_address $(ETCD_SERVER):$(ETCD_PORT) --topo_global_root /vitess/global" 232 - name: VTTABLET_PORT 233 value: "15100" 234 - name: VTTABLET_GRPC_PORT 235 value: "16100" 236 - name: VTCTLD_HOST 237 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 238 - name: VTCTLD_WEB_PORT 239 value: "15000" 240 - name: SERVICE_PORT 241 value: "$(VTTABLET_PORT)" 242 - name: MYSQL_ROOT_USER 243 valueFrom: 244 secretKeyRef: 245 name: $(CONN_CREDENTIAL_SECRET_NAME) 246 key: username 247 optional: false 248 - name: MYSQL_ROOT_PASSWORD 249 valueFrom: 250 secretKeyRef: 251 name: $(CONN_CREDENTIAL_SECRET_NAME) 252 key: password 253 optional: false 254 command: ["/scripts/vttablet.sh"] 255 volumeMounts: 256 - name: scripts 257 mountPath: /scripts 258 - name: mysql-scale-config 259 mountPath: /conf 260 - name: data 261 mountPath: /vtdataroot 262 volumes: 263 {{- if .Values.logCollector.enabled }} 264 - name: log-data 265 hostPath: 266 path: /var/log/kubeblocks 267 type: DirectoryOrCreate 268 {{- end }} 269 - name: annotations 270 downwardAPI: 271 items: 272 - path: "leader" 273 fieldRef: 274 fieldPath: metadata.annotations['cs.apps.kubeblocks.io/leader'] 275 - path: "component-replicas" 276 fieldRef: 277 fieldPath: metadata.annotations['apps.kubeblocks.io/component-replicas'] 278 systemAccounts: 279 cmdExecutorConfig: 280 image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} 281 command: 282 - mysql 283 args: 284 - -u$(MYSQL_ROOT_USER) 285 - -p$(MYSQL_ROOT_PASSWORD) 286 - -h$(KB_ACCOUNT_ENDPOINT) 287 - -e 288 - $(KB_ACCOUNT_STATEMENT) 289 env: 290 - name: MYSQL_ROOT_USER 291 valueFrom: 292 secretKeyRef: 293 name: $(CONN_CREDENTIAL_SECRET_NAME) 294 key: username 295 optional: false 296 - name: MYSQL_ROOT_PASSWORD 297 valueFrom: 298 secretKeyRef: 299 name: $(CONN_CREDENTIAL_SECRET_NAME) 300 key: password 301 optional: false 302 passwordConfig: 303 length: 10 304 numDigits: 5 305 numSymbols: 0 306 letterCase: MixedCases 307 accounts: 308 - name: kbadmin 309 provisionPolicy: 310 type: CreateByStmt 311 scope: AnyPods 312 statements: 313 creation: CREATE USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; GRANT ALL PRIVILEGES ON *.* TO $(USERNAME); 314 update: ALTER USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; 315 - name: kbdataprotection 316 provisionPolicy: 317 type: CreateByStmt 318 scope: AnyPods 319 statements: 320 creation: CREATE USER $(USERNAME) IDENTIFIED BY '$(PASSWD)';GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO $(USERNAME); GRANT LOCK TABLES,RELOAD,PROCESS,REPLICATION CLIENT, SUPER,SELECT,EVENT,TRIGGER,SHOW VIEW ON *.* TO $(USERNAME); 321 update: ALTER USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; 322 - name: kbprobe 323 provisionPolicy: &kbReadonlyAcctRef 324 type: CreateByStmt 325 scope: AnyPods 326 statements: 327 creation: CREATE USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; GRANT REPLICATION CLIENT, PROCESS ON *.* TO $(USERNAME); GRANT SELECT ON performance_schema.* TO $(USERNAME); 328 update: ALTER USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; 329 - name: kbmonitoring 330 provisionPolicy: *kbReadonlyAcctRef 331 - name: kbreplicator 332 provisionPolicy: 333 type: CreateByStmt 334 scope: AnyPods 335 statements: 336 creation: CREATE USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; GRANT REPLICATION SLAVE ON *.* TO $(USERNAME) WITH GRANT OPTION; 337 update: ALTER USER $(USERNAME) IDENTIFIED BY '$(PASSWD)'; 338 - name: vtcontroller 339 characterType: vtcontroller 340 workloadType: Stateful 341 volumeTypes: 342 - name: data 343 type: data 344 scriptSpecs: 345 - name: apecloud-mysql-scripts 346 templateRef: apecloud-mysql-scripts 347 namespace: {{ .Release.Namespace }} 348 volumeName: scripts 349 defaultMode: 0555 350 configSpecs: 351 - name: vtconsensus-config 352 templateRef: vtconsensus-config-template 353 constraintRef: mysql-scale-vtconsensus-config-constraints 354 volumeName: mysql-scale-config 355 namespace: {{ .Release.Namespace }} 356 logConfigs: 357 {{- range $name,$pattern := .Values.vtconsensusLogConfigs }} 358 - name: {{ $name }} 359 filePathPattern: {{ $pattern }} 360 {{- end }} 361 podSpec: 362 containers: 363 - name: vtconsensus 364 imagePullPolicy: {{ default "IfNotPresent" .Values.wesqlscale.image.pullPolicy }} 365 ports: 366 - containerPort: 16000 367 name: port 368 env: 369 - name: CELL 370 value: {{ .Values.wesqlscale.cell | default "zone1" | quote }} 371 - name: MYSQL_ROOT_USER 372 valueFrom: 373 secretKeyRef: 374 name: $(CONN_CREDENTIAL_SECRET_NAME) 375 key: username 376 optional: false 377 - name: MYSQL_ROOT_PASSWORD 378 valueFrom: 379 secretKeyRef: 380 name: $(CONN_CREDENTIAL_SECRET_NAME) 381 key: password 382 optional: false 383 - name: VTCONSENSUS_PORT 384 value: "16000" 385 - name: ETCD_SERVER 386 value: "localhost" 387 - name: ETCD_PORT 388 value: "2379" 389 - name: TOPOLOGY_FLAGS 390 value: "--topo_implementation etcd2 --topo_global_server_address $(ETCD_SERVER):$(ETCD_PORT) --topo_global_root /vitess/global" 391 command: ["/scripts/vtconsensus.sh"] 392 volumeMounts: 393 - name: scripts 394 mountPath: /scripts 395 - name: mysql-scale-config 396 mountPath: /conf 397 - name: data 398 mountPath: /vtdataroot 399 - name: etcd 400 imagePullPolicy: {{ default "IfNotPresent" .Values.wesqlscale.image.pullPolicy }} 401 ports: 402 - containerPort: 2379 403 name: etcd-client 404 env: 405 - name: CELL 406 value: {{ .Values.wesqlscale.cell | default "zone1" | quote }} 407 - name: ETCDCTL_API 408 value: "2" 409 - name: ETCD_SERVER 410 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 411 - name: ETCD_PORT 412 value: "2379" 413 - name: TOPOLOGY_FLAGS 414 value: "--topo_implementation etcd2 --topo_global_server_address $(ETCD_SERVER):$(ETCD_PORT) --topo_global_root /vitess/global" 415 command: ["/scripts/etcd.sh"] 416 volumeMounts: 417 - name: scripts 418 mountPath: /scripts 419 - name: data 420 mountPath: /vtdataroot 421 lifecycle: 422 postStart: 423 exec: 424 command: ["/scripts/etcd-post-start.sh"] 425 - name: vtctld 426 imagePullPolicy: {{ default "IfNotPresent" .Values.wesqlscale.image.pullPolicy }} 427 ports: 428 - containerPort: 15000 429 name: vtctld-webport 430 - containerPort: 15999 431 name: vtctld-grpcport 432 env: 433 - name: CELL 434 value: {{ .Values.wesqlscale.cell | default "zone1" | quote }} 435 - name: VTCTLD_SERVER 436 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 437 - name: VTCTLD_WEB_PORT 438 value: "15000" 439 - name: VTCTLD_GRPC_PORT 440 value: "15999" 441 - name: ETCD_SERVER 442 value: "localhost" 443 - name: ETCD_PORT 444 value: "2379" 445 - name: TOPOLOGY_FLAGS 446 value: "--topo_implementation etcd2 --topo_global_server_address $(ETCD_SERVER):$(ETCD_PORT) --topo_global_root /vitess/global" 447 command: ["/scripts/vtctld.sh"] 448 volumeMounts: 449 - name: scripts 450 mountPath: /scripts 451 - name: data 452 mountPath: /vtdataroot 453 - name: vtgate 454 characterType: mysql 455 workloadType: Stateless 456 scriptSpecs: 457 - name: apecloud-mysql-scripts 458 templateRef: apecloud-mysql-scripts 459 namespace: {{ .Release.Namespace }} 460 volumeName: scripts 461 defaultMode: 0555 462 logConfigs: 463 {{- range $name,$pattern := .Values.vtgateLogConfigs }} 464 - name: {{ $name }} 465 filePathPattern: {{ $pattern }} 466 {{- end }} 467 configSpecs: 468 - name: vtgate-config 469 templateRef: vtgate-config-template 470 constraintRef: mysql-scale-vtgate-config-constraints 471 volumeName: mysql-scale-config 472 namespace: {{ .Release.Namespace }} 473 monitor: 474 builtIn: false 475 exporterConfig: 476 scrapePath: /metrics 477 scrapePort: 15001 478 service: 479 ports: 480 - name: serverport 481 port: 15306 482 targetPort: serverport 483 podSpec: 484 initContainers: 485 - name: wait-vtctld-ready 486 imagePullPolicy: IfNotPresent 487 image: busybox:1.35 488 env: 489 - name: VTCTLD_HOST 490 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 491 - name: VTCTLD_GRPC_PORT 492 value: "15999" 493 command: ["/scripts/wait-for-service.sh", "vtctld", "$(VTCTLD_HOST)", "$(VTCTLD_GRPC_PORT)"] 494 volumeMounts: 495 - name: scripts 496 mountPath: /scripts 497 containers: 498 - name: vtgate 499 imagePullPolicy: IfNotPresent 500 ports: 501 - containerPort: 15001 502 name: webport 503 - containerPort: 15991 504 name: grpcport 505 - containerPort: 15306 506 name: serverport 507 env: 508 - name: MYSQL_ROOT_USER 509 valueFrom: 510 secretKeyRef: 511 name: $(CONN_CREDENTIAL_SECRET_NAME) 512 key: username 513 optional: false 514 - name: MYSQL_ROOT_PASSWORD 515 valueFrom: 516 secretKeyRef: 517 name: $(CONN_CREDENTIAL_SECRET_NAME) 518 key: password 519 optional: false 520 - name: CELL 521 value: {{ .Values.wesqlscale.cell | default "zone1" | quote }} 522 - name: SERVICE_PORT 523 value: "15001" 524 - name: VTGATE_MYSQL_PORT 525 value: "15306" 526 - name: VTGATE_WEB_PORT 527 value: "15001" 528 - name: VTGATE_GRPC_PORT 529 value: "15991" 530 - name: ETCD_SERVER 531 value: "$(KB_CLUSTER_NAME)-vtcontroller-headless" 532 - name: ETCD_PORT 533 value: "2379" 534 - name: TOPOLOGY_FLAGS 535 value: "--topo_implementation etcd2 --topo_global_server_address $(ETCD_SERVER):$(ETCD_PORT) --topo_global_root /vitess/global" 536 - name: MYSQL_UNIX_PORT 537 value: "/tmp/mysql.sock" 538 command: ["/scripts/vtgate.sh"] 539 volumeMounts: 540 - name: scripts 541 mountPath: /scripts 542 - name: mysql-scale-config 543 mountPath: /conf