通过helm在k8s中安装mysql 8.0.37

发布于:2025-04-18 ⋅ 阅读:(16) ⋅ 点赞:(0)

使用 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.tgz

cd 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: true
  database: "test"
  username: "test"
  password: "your_password"
  replicationUser: replicator
  replicationPassword: ""
  existingSecret: ""
  usePasswordFiles: false
  customPasswordFiles: {}

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: true
    namespace: ""
    additionalLabels: {}
    rules:
     - alert: Mysql-Down
       expr: absent(up{job="mysql"} == 1)
       for: 5m
       labels:
         severity: warning
         service: mariadb
       annotations:
         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

网站公告

今日签到

点亮在社区的每一天
去签到