Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

K8s starts the process of mysql master and slave

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "the process of k8s starting mysql master and slave". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Start two docker, and the service is in mysql master-slave mode

First, you need to build two docker, using the image of mysql5.7 as the base image.

1. Mysql-master Dockerfile

FROM mysql:latestRUN cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime & & echo "Asia/shanghai" > > / etc/timezoneCOPY mysqld.cnf / etc/mysql/mysql.conf.d/mysqld.cnfCOPY entrypoint.sh / COPY init-master.sh / docker-entrypoint-initdb.d/

Execute the following command in the current directory:

Docker built-t mysql-master:v1.0.

For other files, please refer to the GitHub link address at the end of the article

2. Mysql-slave Dockerfile

FROM mysql:latestRUN cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime & & echo "Asia/shanghai" > > / etc/timezoneCOPY mysqld.cnf / etc/mysql/mysql.conf.d/COPY entrypoint.sh / COPY slave-init.sh / docker-entrypoint-initdb.d/

Execute the following command in the current directory:

Docker built-t mysql-slave:v1.0.

For other files, please refer to the GitHub link address at the end of the article

3. Execute the yaml file master of K8s, filename: mysql-master.yaml

Make sure there is a / data/mysql_data directory locally

ApiVersion: v1kind: Podmetadata: name: master-tdbwv labels: name: master-tdbwvspec: 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: v1kind: Servicemetadata: name: master-tdbwv labels: name: master-tdbwvspec: type: NodePort ports: -port: 3306 nodePort: selector: name: master-tdbwv

4. Execute the yaml file slave of K8s, filename: mysql-slave.yaml

Make sure there is a / data/mysql_slave_data directory locally

ApiVersion: v1kind: Podmetadata: name: slave-ncrxq labels: name: slave-ncrxqspec: 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 : v1kind: Servicemetadata: name: slave-ncrxq labels: name: slave-ncrxqspec: type: NodePort ports:-port: 3306 nodePort: selector: name: slave-ncrxq "the process of k8s starting mysql master and slave" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report