1.首先建立密码的秘钥
在配置中心建立秘钥:mysql-secret
key为:MYSQL_ROOT_PASSWORD,值数据库密码
2.建立mysql的配置文件
在配置中心的配置
新建配置:mysqld
key为:mysqld.cnf
值如下:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
lower_case_table_names =1
max_connections=2000
max_allowed_packet=40M
log_timestamps = SYSTEM
symbolic-links=0
3.建立mysql挂载data挂载目录
在存储卷建立mysql挂载目录,存放data数据
4.在工作负载进行部署mysql5.7
下一步
挂载data目录
选择添加已有存储卷,挂载路径为:/var/lib/mysql
挂载配置文件
选择引用配置中心
其对应的yaml如下:
kind: Deployment
apiVersion: apps/v1
metadata:
name: mysql
namespace: base-config
resourceVersion: '601345'
labels:
app: mysql
annotations:
deployment.kubernetes.io/revision: '16'
kubesphere.io/isElasticReplicas: 'false'
maxSurgePod: '2'
minAvailablePod: '1'
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
creationTimestamp: null
labels:
app: mysql
spec:
volumes:
- name: volume-daisqd
persistentVolumeClaim:
claimName: mysql
- name: volume-tdb72k
configMap:
name: mysqld
items:
- key: mysqld.cnf
path: mysqld.cnf
defaultMode: 420
containers:
- name: container-e8ak1r
image: 'mysql:5.7'
ports:
- name: port
containerPort: 3306
protocol: TCP
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD
resources:
limits:
cpu: '8'
memory: 16Gi
requests:
cpu: '4'
memory: 8Gi
volumeMounts:
- name: volume-daisqd
mountPath: /var/lib/mysql
- name: volume-tdb72k
mountPath: /etc/mysql/mysql.conf.d
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0%
maxSurge: 100%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
保存后更新后就要配置服务,就是对外围暴露端口
建立服务mysql-service
然后点击保存,点击编辑外网访问,就会生出对外网访问的端口