# MySQL 云环境部署
# Namespace
$ kubectl create namespace devops
# 配置文件
mysql-config.yml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-config
namespace: devops
data:
my.cnf: |-
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
port=3306
character-set-client-handshake = FALSE
# character-set-server = utf8
# collation-server = utf8_unicode_ci
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1
innodb_large_prefix = ON
innodb_file_format = Barracuda
innodb_file_format_check = ON
innodb_file_format_max = Barracuda
innodb_file_per_table = ON
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet=256MB
max_connections=1000
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# datadir=/var/lib/mysql
# socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# log-error=/var/log/mysqld.log
# pid-file=/var/run/mysqld/mysqld.pid
# 部署
mysql-deployment.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: devops
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: 172.16.62.204:30085/puyuan/mysql:5.7.32
imagePullPolicy: Always
env:
- name: MYSQL_DATABASE
value: devops
- name: MYSQL_ROOT_PASSWORD
value: password
ports:
- containerPort: 3306
name: port
protocol: TCP
resources:
limits:
cpu: 1000m
memory: 2Gi
requests:
cpu: 1000m
memory: 2Gi
volumeMounts:
- name: config
mountPath: /etc/mysql/mysql.conf.d/my.cnf # MySQL配置文件路径
subPath: my.cnf
- name: data
mountPath: /var/lib/mysql # MySQL数据存储目录
volumes:
- name: config
configMap:
defaultMode: 0644
name: mysql-config
- name: data
persistentVolumeClaim:
claimName: mysql-data
# 服务暴漏
mysql-svc.yml
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: devops
labels:
app: mysql
spec:
selector:
app: mysql
type: NodePort
ports:
- name: port
port: 3306
targetPort: port
nodePort: 30006