update prod mysql

main
ycz008 2024-04-10 17:40:31 +08:00
parent 6181f67e85
commit 4458eddccf
4 changed files with 304 additions and 28 deletions

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: mysql-m-cnf name: mysql-0-cnf
data: data:
config: |- config: |-
[mysqld] [mysqld]
@ -41,17 +41,17 @@ data:
apiVersion: apps/v1 apiVersion: apps/v1
kind: StatefulSet kind: StatefulSet
metadata: metadata:
name: mysql-m name: mysql-0
spec: spec:
replicas: 1 replicas: 1
serviceName: mysql serviceName: mysql
selector: selector:
matchLabels: matchLabels:
app: mysql-m app: mysql-0
template: template:
metadata: metadata:
labels: labels:
app: mysql-m app: mysql-0
spec: spec:
initContainers: initContainers:
- name: init - name: init
@ -69,7 +69,7 @@ spec:
securityContext: securityContext:
privileged: true privileged: true
volumeMounts: volumeMounts:
- name: mysql-m - name: mysql-0
mountPath: /var/lib/mysql mountPath: /var/lib/mysql
containers: containers:
- name: mysql - name: mysql
@ -91,19 +91,19 @@ spec:
name: mysql name: mysql
key: mysql_apps key: mysql_apps
volumeMounts: volumeMounts:
- name: mysql-m - name: mysql-0
mountPath: /var/lib/mysql mountPath: /var/lib/mysql
- name: mysql-m-cnf - name: mysql-0-cnf
mountPath: /etc/my.cnf mountPath: /etc/my.cnf
subPath: my.cnf subPath: my.cnf
readOnly: true readOnly: true
volumes: volumes:
- name: mysql-m - name: mysql-0
hostPath: hostPath:
path: /data/prod/mysql-m path: /data/prod/mysql-0
- name: mysql-m-cnf - name: mysql-0-cnf
configMap: configMap:
name: mysql-m-cnf name: mysql-0-cnf
items: items:
- key: config - key: config
path: my.cnf path: my.cnf
@ -125,14 +125,14 @@ spec:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: mysql-m name: mysql-0
labels: labels:
app: mysql-m app: mysql-0
spec: spec:
ports: ports:
- protocol: TCP - protocol: TCP
port: 3306 port: 3306
targetPort: 3306 targetPort: 3306
selector: selector:
app: mysql-m app: mysql-0
type: ClusterIP type: ClusterIP

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: mysql-s-cnf name: mysql-1-cnf
data: data:
config: |- config: |-
[mysqld] [mysqld]
@ -41,17 +41,17 @@ data:
apiVersion: apps/v1 apiVersion: apps/v1
kind: StatefulSet kind: StatefulSet
metadata: metadata:
name: mysql-s name: mysql-1
spec: spec:
replicas: 1 replicas: 1
serviceName: mysql serviceName: mysql
selector: selector:
matchLabels: matchLabels:
app: mysql-s app: mysql-1
template: template:
metadata: metadata:
labels: labels:
app: mysql-s app: mysql-1
spec: spec:
initContainers: initContainers:
- name: init - name: init
@ -69,7 +69,7 @@ spec:
securityContext: securityContext:
privileged: true privileged: true
volumeMounts: volumeMounts:
- name: mysql-s - name: mysql-1
mountPath: /var/lib/mysql mountPath: /var/lib/mysql
containers: containers:
- name: mysql - name: mysql
@ -91,19 +91,19 @@ spec:
name: mysql name: mysql
key: mysql_apps key: mysql_apps
volumeMounts: volumeMounts:
- name: mysql-s - name: mysql-1
mountPath: /var/lib/mysql mountPath: /var/lib/mysql
- name: mysql-s-cnf - name: mysql-1-cnf
mountPath: /etc/my.cnf mountPath: /etc/my.cnf
subPath: my.cnf subPath: my.cnf
readOnly: true readOnly: true
volumes: volumes:
- name: mysql-s - name: mysql-1
hostPath: hostPath:
path: /data/prod/mysql-s path: /data/prod/mysql-1
- name: mysql-s-cnf - name: mysql-1-cnf
configMap: configMap:
name: mysql-s-cnf name: mysql-1-cnf
items: items:
- key: config - key: config
path: my.cnf path: my.cnf
@ -125,14 +125,14 @@ spec:
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: mysql-s name: mysql-1
labels: labels:
app: mysql-s app: mysql-1
spec: spec:
ports: ports:
- protocol: TCP - protocol: TCP
port: 3306 port: 3306
targetPort: 3306 targetPort: 3306
selector: selector:
app: mysql-s app: mysql-1
type: ClusterIP type: ClusterIP

View File

@ -0,0 +1,138 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-2-cnf
data:
config: |-
[mysqld]
bind-address=0.0.0.0
port=3306
skip-name-resolve
datadir=/var/lib/mysql/data
log_bin=/var/lib/mysql/logs/bin-log
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/mysqld.pid
log-error=/var/lib/mysql/logs/mysqld.log
max_allowed_packet=16M
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# Extended
max_connections=5000
binlog_format=row
binlog_expire_logs_seconds=2592000
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
innodb_buffer_pool_size=4G
innodb_log_file_size=1G
innodb_flush_log_at_trx_commit=2
sync_binlog=0
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8mb4
[manager]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/mysqld.pid
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql-2
spec:
replicas: 1
serviceName: mysql
selector:
matchLabels:
app: mysql-2
template:
metadata:
labels:
app: mysql-2
spec:
initContainers:
- name: init
image: busybox
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
sysctl -w net.ipv4.tcp_keepalive_time=300
sysctl -w net.ipv4.tcp_keepalive_intvl=10
sysctl -w net.ipv4.tcp_keepalive_probes=3
mkdir -p /var/lib/mysql/logs
chown -R 999:999 /var/lib/mysql
securityContext:
privileged: true
volumeMounts:
- name: mysql-2
mountPath: /var/lib/mysql
containers:
- name: mysql
image: mysql:8.0.33
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: mysql_root
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql
key: mysql_user
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: mysql_apps
volumeMounts:
- name: mysql-2
mountPath: /var/lib/mysql
- name: mysql-2-cnf
mountPath: /etc/my.cnf
subPath: my.cnf
readOnly: true
volumes:
- name: mysql-2
hostPath:
path: /data/prod/mysql-2
- name: mysql-2-cnf
configMap:
name: mysql-2-cnf
items:
- key: config
path: my.cnf
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/hostname"
operator: In
values:
- bfs-k8snode-10-2-2-91.hetzner.base.beaconfireinc.com
tolerations:
- key: "app.kubernetes.io/component"
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-2
labels:
app: mysql-2
spec:
ports:
- protocol: TCP
port: 3306
targetPort: 3306
selector:
app: mysql-2
type: ClusterIP

View File

@ -0,0 +1,138 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-3-cnf
data:
config: |-
[mysqld]
bind-address=0.0.0.0
port=3306
skip-name-resolve
datadir=/var/lib/mysql/data
log_bin=/var/lib/mysql/logs/bin-log
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/mysqld.pid
log-error=/var/lib/mysql/logs/mysqld.log
max_allowed_packet=16M
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# Extended
max_connections=5000
binlog_format=row
binlog_expire_logs_seconds=2592000
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
innodb_buffer_pool_size=4G
innodb_log_file_size=1G
innodb_flush_log_at_trx_commit=2
sync_binlog=0
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8mb4
[manager]
port=3306
socket=/var/lib/mysql/mysql.sock
pid-file=/var/lib/mysql/mysqld.pid
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql-3
spec:
replicas: 1
serviceName: mysql
selector:
matchLabels:
app: mysql-3
template:
metadata:
labels:
app: mysql-3
spec:
initContainers:
- name: init
image: busybox
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- |
sysctl -w net.ipv4.tcp_keepalive_time=300
sysctl -w net.ipv4.tcp_keepalive_intvl=10
sysctl -w net.ipv4.tcp_keepalive_probes=3
mkdir -p /var/lib/mysql/logs
chown -R 999:999 /var/lib/mysql
securityContext:
privileged: true
volumeMounts:
- name: mysql-3
mountPath: /var/lib/mysql
containers:
- name: mysql
image: mysql:8.0.33
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: mysql_root
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql
key: mysql_user
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: mysql_apps
volumeMounts:
- name: mysql-3
mountPath: /var/lib/mysql
- name: mysql-3-cnf
mountPath: /etc/my.cnf
subPath: my.cnf
readOnly: true
volumes:
- name: mysql-3
hostPath:
path: /data/prod/mysql-3
- name: mysql-3-cnf
configMap:
name: mysql-3-cnf
items:
- key: config
path: my.cnf
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "kubernetes.io/hostname"
operator: In
values:
- bfs-k8snode-10-2-2-90.hetzner.base.beaconfireinc.com
tolerations:
- key: "app.kubernetes.io/component"
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-3
labels:
app: mysql-3
spec:
ports:
- protocol: TCP
port: 3306
targetPort: 3306
selector:
app: mysql-3
type: ClusterIP