生产中k8s适合mysql_k8s mysql 单点部署

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

20-nproc.conf

*soft nproc unlimited

root 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 = 11port= 3306user=mysql

autocommit= 1character_set_server=utf8mb4

skip_name_resolve= 1max_connections= 3000max_connect_errors= 1000transaction_isolation= READ-COMMITTED

join_buffer_size=128M

tmp_table_size=64M

tmpdir= /tmp

max_allowed_packet=64M

interactive_timeout= 1200wait_timeout= 600read_buffer_size=16M

read_rnd_buffer_size=8M

sort_buffer_size=8M

explicit_defaults_for_timestamp=true

Dockerfile

[root@harbor mysql5.7.20]# cat Dockerfile

FROM docker.io/mysql:5.7.20MAINTAINER fengjianENV TZ"Asia/Shanghai"ENV TERM xterm

ENV MALLOC_ARENA_MAX=1ADD localtime/etc/ADD20-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: v1

kind: Secret

metadata:

name: mysql-secretsnamespace: prodpay

#type: Opaque

data:

root-password: QWJjZCwxMj222M0

[root@master1 mysql]# cat mysql_pvc.yaml

kind: PersistentVolumeClaim

apiVersion: v1

metadata:namespace: prodpay

name: mysql-pvc

spec:

storageClassName: ceph-rbd-dalianpay

accessModes:-ReadWriteOnce

resources:

requests:

storage: 100Gi

[root@master1 mysql]# cat mysql.yaml

apiVersion: apps/v1beta2

kind: Deployment

metadata:

name: mysqlnamespace: prodpay

spec:

selector:

matchLabels:

app: mysql

replicas:1template:

metadata:

labels:

app: mysql

spec:

containers:- image: 192.168.200.10/source/mysql:5.7.20imagePullPolicy: Always

name: mysql

#command: ["rm","-rf","/var/lib/mysql/lost+found"]

ports:- containerPort: 3306resources:

requests:

cpu:4memory: 4Gi

limits:

cpu:8memory: 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: v1

kind: Service

metadata:

name: mysqlnamespace: prodpay

spec:

ports:-name: mqsql

port:3306targetPort:3306selector:

app: mysq

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值