k8s启动mysql主从的过程
本篇内容介绍了“k8s启动MySQL主从的过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
成都创新互联专业为企业提供南靖网站建设、南靖做网站、南靖网站设计、南靖网站制作等企业网站建设、网页设计与制作、南靖企业网站模板建站服务,十年南靖做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
启动两个docker ,服务为mysql主从模式;
首先需要构建两个docker,使用mysql5.7的镜像作为基础镜像
1. mysql-master Dockerfile
FROM mysql:latest RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/shanghai" >> /etc/timezone COPY mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf COPY entrypoint.sh / COPY init-master.sh /docker-entrypoint-initdb.d/
在当前目录下执行如下命令:
docker built -t mysql-master:v1.0 .
其他文件请参照文章末尾的GitHub链接地址
2. mysql-slave Dockerfile
FROM mysql:latest RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/shanghai" >> /etc/timezone COPY mysqld.cnf /etc/mysql/mysql.conf.d/ COPY entrypoint.sh / COPY slave-init.sh /docker-entrypoint-initdb.d/
在当前目录下执行如下命令:
docker built -t mysql-slave:v1.0 .
其他文件请参照文章末尾的GitHub链接地址
3. 执行k8s 的yaml文件 master, 文件名:mysql-master.yaml
确保本地有 /data/mysql_data目录
apiVersion: v1 kind: Pod metadata: name: master-tdbwv labels: name: master-tdbwv spec: volumes: - name: data hostPath: path: /data/mysql_data containers: - name: master-tdbwv image: mysql-master:v1.0 env: - name: MYSQL_ROOT_PASSWORD value: uggTKd3xsIMM - name: MYSQL_REPLICATION_USER value: repl - name: MYSQL_REPLICATION_PASSWORD value: RQfUjBff ports: - containerPort: 3306 name: master-tdbwv volumeMounts: - name: data mountPath: /var/lib/mysql resources: limits: cpu: 2 memory: 200Mi nodeName: localhost --- apiVersion: v1 kind: Service metadata: name: master-tdbwv labels: name: master-tdbwv spec: type: NodePort ports: - port: 3306 nodePort: selector: name: master-tdbwv
4. 执行k8s 的yaml文件 slave, 文件名:mysql-slave.yaml
确保本地有 /data/mysql_slave_data目录
apiVersion: v1 kind: Pod metadata: name: slave-ncrxq labels: name: slave-ncrxq spec: volumes: - name: data hostPath: path: /data/mysql_slave_data containers: - name: slave-ncrxq image: mysql-slave:v1.0 env: - name: MYSQL_ROOT_PASSWORD value: uggTKd3xsIMM - name: MYSQL_REPLICATION_USER value: repl - name: MYSQL_REPLICATION_PASSWORD value: RQfUjBff - name: MYSQL_MASTER_SERVICE_HOST value: 127.0.0.1 ports: - containerPort: 3306 name: slave-ncrxq volumeMounts: - name: data mountPath: /var/lib/mysql resources: limits: cpu: 2 memory: 200Mi nodeName: localhost --- apiVersion: v1 kind: Service metadata: name: slave-ncrxq labels: name: slave-ncrxq spec: type: NodePort ports: - port: 3306 nodePort: selector: name: slave-ncrxq
“k8s启动mysql主从的过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
本文名称:k8s启动mysql主从的过程
当前路径:http://myzitong.com/article/ieegih.html