本篇内容介绍了“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主从的过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。