| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- ---
- # 1. ConfigMaps
- apiVersion: v1
- kind: ConfigMap
- metadata:
- name: mysql-master-config
- data:
- my.cnf: |
- [mysqld]
- server-id=1
- log-bin=mysql-bin
- binlog-format=ROW
- gtid-mode=ON
- enforce-gtid-consistency=ON
- log-replica-updates=ON
- skip-replica-start=ON
- default-authentication-plugin=mysql_native_password
- bind-address=0.0.0.0
- character-set-server=utf8mb4
- collation-server=utf8mb4_unicode_ci
- max_connections=1000
- innodb_buffer_pool_size=256M
- ---
- # 2. Secrets
- apiVersion: v1
- kind: Secret
- metadata:
- name: mysql-secrets
- type: Opaque
- stringData:
- root-password: "Lq123456!"
- replica-user: "replica"
- replica-password: "Replica123456!"
- ---
- # 3. Services
- apiVersion: v1
- kind: Service
- metadata:
- name: mysql-master
- labels:
- app: mysql
- role: master
- spec:
- ports:
- - port: 3306
- name: mysql
- selector:
- app: mysql
- role: master
- ---
- # 4. Master Deployment (先用Deployment简化调试)
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: mysql-master
- labels:
- app: mysql
- role: master
- spec:
- replicas: 1
- selector:
- matchLabels:
- app: mysql
- role: master
- strategy:
- type: Recreate
- template:
- metadata:
- labels:
- app: mysql
- role: master
- spec:
- containers:
- - name: mysql
- image: mysql:8.0.44
- env:
- - name: MYSQL_ROOT_PASSWORD
- value: "Lq123456!"
- - name: MYSQL_DATABASE
- value: "appdb"
- - name: MYSQL_USER
- value: "appuser"
- - name: MYSQL_PASSWORD
- value: "App123456!"
- ports:
- - containerPort: 3306
- volumeMounts:
- - name: config
- mountPath: /etc/mysql/conf.d/
- - name: data
- mountPath: /var/lib/mysql
- resources:
- requests:
- memory: "512Mi"
- cpu: "250m"
- livenessProbe:
- tcpSocket:
- port: 3306
- initialDelaySeconds: 90
- periodSeconds: 20
- readinessProbe:
- exec:
- command:
- - mysql
- - -h127.0.0.1
- - -uroot
- - -pLq123456!
- - -e
- - "SELECT 1"
- initialDelaySeconds: 60
- periodSeconds: 10
- lifecycle:
- postStart:
- exec:
- command:
- - /bin/bash
- - -c
- - |
- sleep 20
- mysql -uroot -pLq123456! <<EOF
- CREATE USER IF NOT EXISTS 'replica'@'%' IDENTIFIED WITH mysql_native_password BY 'Replica123456!';
- GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replica'@'%';
- GRANT SELECT ON *.* TO 'replica'@'%';
- FLUSH PRIVILEGES;
- SHOW MASTER STATUS\G
- EOF
- volumes:
- - name: config
- configMap:
- name: mysql-master-config
- - name: data
- emptyDir: {}
|