• helm一键 安装mariadb-ha(详细)


    一、

    二、单机安装一主一从

      先创建对应pv

       https://github.com/helm/charts/blob/master/stable/mariadb/templates/master-statefulset.yaml

           mysql-ha-pv00.yaml

    apiVersion: v1
    kind: PersistentVolume
    metadata:
          name: mariadb-master
          labels:
            app: mariadb
    spec:
     capacity:
      storage: 10Gi
     accessModes:
      - ReadWriteOnce
     hostPath:
      path: /opt/mariadb-master

       mysql-ha-pv01.yaml

    apiVersion: v1
    kind: PersistentVolume
    metadata:
          name: mariadb-slave
          labels:
            app: mariadb
    spec:
     capacity:
      storage: 10Gi
     accessModes:
      - ReadWriteOnce
     hostPath:
      path: /opt/mariadb-slave

      kubectl create -f mysql-ha-pv00.yaml
      kubectl create -f mysql-ha-pv01.yaml

    三、安装mysql

      #修改密码和修改主库的pvc,默认都有pvc

     helm install --name mariadb-ha --set rootUser.password="123456",replication.password="rep123456"  stable/mariadb

          #启动后查看pod容器日志,提示没权限创建目录或初始化失败,需要修改宿主目录的权限为1001,因为容器默认以1001的用户启动

       chown 1001:root /opt/mariadb-master

          chown 1001:root /opt/mariadb-slave

       kubectl get all查看是否成功

    四、安装成功后,测试

    查看mysql密码

    kubectl get secret --namespace default mariadb-ha -o jsonpath="{.data.mariadb-root-password}" | base64 --decode
    #启动客户端测试
    kubectl run mariadb-ha-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mariadb:10.1.38 --namespace default --command -- bash
    #连接mysql server
    mysql -h mariadb-ha.default.svc.cluster.local -uroot -pdu123456
    #创建表

    create table test(
    id int
    );

    五、扩容一台从库

    5.1 先创建pv

      mysql-ha-pv02.yaml 

    apiVersion: v1
    kind: PersistentVolume
    metadata:
          name: mariadb-slave02
          labels:
            app: mariadb
    spec:
     capacity:
      storage: 10Gi
     accessModes:
      - ReadWriteOnce
     hostPath:
      path: /opt/mariadb-slave02

      kubectl create -f  mysql-ha-pv02.yaml 

    5.2 创建values

      mysql-ha-values-upgrade.yaml

    slave:
      replicas: 2
    rootUser:
      password: 123456
    replication:
      password: rep123456

    5.3授权目录

       chown 1001:root /opt/mariadb-slave02

    5.4更新

    helm upgrade -f mysql-ha-values-upgrade.yaml  mariadb-ha stable/mariadb
  • 相关阅读:
    python中的基础坑
    Django组件content-type使用方法详解
    数据库范式
    MySQL常见面试题索引、表设计
    python操作MySQL之pymysql模块
    MySQL备份与还原
    MySQL查询缓存
    MySQL索引及查询优化
    MySQL事务隔离之MVCC版本控制
    MySQL事务及实现、隔离级别及锁与优化
  • 原文地址:https://www.cnblogs.com/kevincaptain/p/10636271.html
Copyright © 2020-2023  润新知