apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: mysql
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7.35
ports:
- containerPort: 3316
resources:
limits:
memory: "2048Mi"
cpu: "1000m"
requests:
memory: "2048Mi"
cpu: "1000m"
volumeMounts:
- name: mysql-conf
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
- name: mysql-hostpath
mountPath: /var/lib/mysql
env:
- name: TZ
value: Asia/Shanghai
- name: MYSQL_ROOT_PASSWORD
value: "123456"
volumes:
- name: mysql-conf
configMap:
name: mysql-conf
items:
- key: my.cnf
path: my.cnf
- name: mysql-hostpath
hostPath:
path: /data/mysql/data
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
app: mysql
spec:
type: NodePort
ports:
- port: 3316
name: mysql
targetPort: 3316
nodePort: 31316
selector:
app: mysql
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-conf
labels:
app: mysql
data:
my.cnf: |
[mysqld]
user=mysql
port=3316
datadir=/var/lib/mysql
character-set-server=utf8
max_connections = 1000
log-error = /var/log/mysql/error.log
character-set-server=utf8
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
default-storage-engine=INNODB
lower_case_table_names=1
mysql集成到k8s的yaml
于 2023-07-18 14:50:23 首次发布