k8s mysql 单点部署

参考官网:https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/

20-nproc.conf

* soft nproc unlimitedroot soft nproc unlimited

limits.conf

# End of file* soft core 0* hard core 0* soft nofile 655360* hard nofile 655360

 

senyint.conf

[root@harbor mysql5.7.20]# cat senyint.cnf[mysqld]server-id = 11 port = 3306user = mysqlautocommit = 1character_set_server=utf8mb4skip_name_resolve = 1max_connections = 3000max_connect_errors = 1000transaction_isolation = READ-COMMITTEDjoin_buffer_size = 128Mtmp_table_size = 64Mtmpdir = /tmpmax_allowed_packet = 64Minteractive_timeout = 1200wait_timeout = 600read_buffer_size = 16Mread_rnd_buffer_size = 8Msort_buffer_size = 8Mexplicit_defaults_for_timestamp=true

 

Dockerfile

[root@harbor mysql5.7.20]# cat Dockerfile FROM docker.io/mysql:5.7.20MAINTAINER fengjian <fengjian@senyint.com>ENV TZ "Asia/Shanghai"ENV TERM xtermENV MALLOC_ARENA_MAX=1ADD localtime /etc/ADD 20-nproc.conf /etc/security/limits.d/ADD limits.conf /etc/security/ADD senyint.cnf /etc/mysql/mysql.conf.d/ADD senyint.cnf /etc/mysql/conf.d/#RUN rm /var/lib/mysql/lost+found -rf

 

 docker build -t 192.168.200.10/source/mysql:5.7.20 .
 docker push 192.168.200.10/source/mysql:5.7.20

部署到k8s中

[root@master1 mysql]# cat mysql-secret.yaml apiVersion: v1kind: Secretmetadata: name: mysql-secrets namespace: prodpay#type: Opaquedata: root-password: QWJjZCwxMj222M0

[root@master1 mysql]# cat mysql_pvc.yaml kind: PersistentVolumeClaimapiVersion: v1metadata: namespace: prodpay name: mysql-pvcspec: storageClassName: ceph-rbd-dalianpay accessModes: - ReadWriteOnce resources: requests: storage: 100Gi

 

[root@master1 mysql]# cat mysql.yaml apiVersion: apps/v1beta2kind: Deploymentmetadata: name: mysql namespace: prodpayspec: selector: matchLabels: app: mysql replicas: 1 template: metadata: labels: app: mysql spec: containers: - image: 192.168.200.10/source/mysql:5.7.20 imagePullPolicy: Always name: mysql #command: ["rm","-rf","/var/lib/mysql/lost+found"] ports: - containerPort: 3306 resources: requests: cpu: 4 memory: 4Gi limits: cpu: 8 memory: 8Gi env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-secrets key: root-password volumeMounts: - mountPath: /var/lib/mysql subPath: mysql #如果不加subpath,那么就会报[ERROR] --initialize specified but the data directory has files in it. Aborting.目录不为空,使用subpath基础表信息会记录在/var/lib/mysql/mysql下 name: data volumes: - name: data persistentVolumeClaim: claimName: mysql-pvc---apiVersion: v1kind: Servicemetadata: name: mysql namespace: prodpayspec: ports: - name: mqsql port: 3306 targetPort: 3306 selector: app: mysq

 

 

相关文章