下载Helm
wget https://docs.rancher.cn/download/helm/helm-v3.0.3-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/

查看helm版本
helm version
# 添加Helm Chart Repository
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
# 查找mariadb
helm search repo mariadb
# 安装mariadb主从
helm install mariadb —set “master.persistence.enabled=false”,”slave.persistence.enabled=false” stable/mariadb
# 查看已部署的release列表
helm ls
# 测试部署的应用
# 获取mysql连接密码
ROOT_PASSWORD=$(kubectl get secret —namespace default mariadb -o jsonpath=”{.data.mariadb-root-password}” | base64 —decode)

echo $ROOT_PASSWORD

连接进slave
kubectl exec -it mariadb-slave-0 bash
执行
mysql -u root -pxxxx ///xxx为密码
查看主从连接关系

  1. show slave status\G;
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: mariadb
  5. Master_User: replicator
  6. Master_Port: 3306
  7. Connect_Retry: 10
  8. Master_Log_File: mysql-bin.000002
  9. Read_Master_Log_Pos: 342
  10. Relay_Log_File: mysql-relay-bin.000004
  11. Relay_Log_Pos: 641
  12. Relay_Master_Log_File: mysql-bin.000002
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:

使用helm升级应用
helm upgrade mariadb stable/mariadb —set “slave.replicas=2”,”master.persistence.enabled=false”,”slave.persistence.enabled=false”
更新slave数为2,检查
kubectl get pod

NAME READY STATUS RESTARTS AGE mariadb-master-0 1/1 Running 0 14m mariadb-slave-0 1/1 Running 0 14m mariadb-slave-1 1/1 Running 8 14m

查看release的历史纪录
helm history mariadb

helm 回滚
helm rollback mariadb

卸载release
helm uninstall mariadb