一、
二、单机安装一主一从
先创建对应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