OKR/prod-upgrade/mysql/mysql-1.yaml

138 lines
3.2 KiB
YAML
Raw Normal View History

2024-04-02 13:35:15 +08:00
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-s-cnf
data:
config: |-
[mysqld]
bind-address=0.0.0.0
port=3306
skip-name-resolve
datadir=/var/lib/mysql/data
2024-04-02 16:17:50 +08:00
log_bin=/var/lib/mysql/logs/bin-log
2024-04-02 13:35:15 +08:00
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
2024-04-02 15:02:21 +08:00
binlog_format=row
binlog_expire_logs_seconds=2592000
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
2024-04-02 13:35:15 +08:00
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-s
spec:
replicas: 1
serviceName: mysql
selector:
matchLabels:
app: mysql-s
template:
metadata:
labels:
app: mysql-s
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
2024-04-02 15:46:29 +08:00
mkdir -p /var/lib/mysql/logs
2024-04-02 15:42:37 +08:00
chown -R 999:999 /var/lib/mysql
2024-04-02 13:35:15 +08:00
securityContext:
privileged: true
2024-04-02 15:42:37 +08:00
volumeMounts:
2024-04-02 16:28:11 +08:00
- name: mysql-s
2024-04-02 15:42:37 +08:00
mountPath: /var/lib/mysql
2024-04-02 13:35:15 +08:00
containers:
- name: mysql
image: mysql:8.0.33
env:
- name: MYSQL_ROOT_PASSWORD
2024-04-02 16:04:13 +08:00
valueFrom:
secretKeyRef:
name: mysql
key: mysql_root
2024-04-02 13:35:15 +08:00
- name: MYSQL_USER
2024-04-02 16:04:13 +08:00
valueFrom:
secretKeyRef:
name: mysql
key: mysql_user
2024-04-02 13:35:15 +08:00
- name: MYSQL_PASSWORD
2024-04-02 16:04:13 +08:00
valueFrom:
secretKeyRef:
name: mysql
key: mysql_apps
2024-04-02 14:18:34 +08:00
volumeMounts:
2024-04-02 13:35:15 +08:00
- name: mysql-s
mountPath: /var/lib/mysql
- name: mysql-s-cnf
mountPath: /etc/my.cnf
subPath: my.cnf
readOnly: true
volumes:
- name: mysql-s
hostPath:
path: /data/prod/mysql-s
- name: mysql-s-cnf
configMap:
name: mysql-s-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
2024-04-02 14:55:32 +08:00
tolerations:
2024-04-02 14:58:38 +08:00
- key: "app.kubernetes.io/component"
2024-04-02 14:55:32 +08:00
operator: "Equal"
value: "mysql"
effect: "NoSchedule"
2024-04-02 13:35:15 +08:00
---
apiVersion: v1
kind: Service
metadata:
name: mysql-s
labels:
app: mysql-s
spec:
ports:
- protocol: TCP
port: 3306
targetPort: 3306
selector:
app: mysql-s
type: ClusterIP