使用 Helm 在 Kubernetes 中安装 MySQL 8.0.37 是一个相对简单的过程。以下是详细步骤:
下载helm包
#添加 Helm 仓库
helm repo add bitnami https://charts.bitnami.com/bitnami#搜索mysql
helm search repo mysql --versions
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/mysql 9.12.5 8.0.37 MySQL is a fast, reliable, scalable, and easy t...#下载mysql
helm pull bitnami/mysql --version=9.12.5#解压下载的helm包
tar -zxvf mysql-9.12.5.tgzcd mysql
vi values.yaml
编写values.yaml
1.storageClass修改
设置pvc的size的大小
global:imageRegistry: ""imagePullSecrets: []storageClass: "xxxx"
2.image.architecture
standalone : 单机
replication : 集群
architecture: standalone
3.auth
设置用户名密码
auth:rootPassword: "your_root_password"createDatabase: truedatabase: "test"username: "test"password: "your_password"replicationUser: replicatorreplicationPassword: ""existingSecret: ""usePasswordFiles: falsecustomPasswordFiles: {}
4.secondary
image.architecture 为 replication,则生效。
secondary.replicaCount 为备机个数
5.my.cnf配置添加
default_authentication_plugin=caching_sha2_password
lower_case_table_names=1
max_connections=10000
6.resources资源配置
limits & requests
7.metrics
enabled: true
8.监控规则
prometheusRule:enabled: truenamespace: ""additionalLabels: {}rules:- alert: Mysql-Downexpr: absent(up{job="mysql"} == 1)for: 5mlabels:severity: warningservice: mariadbannotations:message: 'MariaDB instance {{`{{`}} $labels.instance {{`}}`}} is down'summary: MariaDB instance is down
安装 MySQL:
helm install <your-release> -f values.yaml .
检查安装后状态
kubectl get pods -l app.kubernetes.io/name: <your-release>
kubectl get secret <your-release>-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode
mysql -h <your-release>-mysql -u root -p