k8s mysql 单点部署

Posted fengjian1585

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

[[email protected] mysql5.7.20]# cat  senyint.cnf
[mysqld]
server-id = 11 
port = 3306
user = mysql
autocommit = 1
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 3000
max_connect_errors = 1000
transaction_isolation = READ-COMMITTED
join_buffer_size = 128M
tmp_table_size = 64M
tmpdir = /tmp
max_allowed_packet = 64M
interactive_timeout = 1200
wait_timeout = 600
read_buffer_size = 16M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
explicit_defaults_for_timestamp=true

 

Dockerfile

[[email protected] mysql5.7.20]# cat Dockerfile 
FROM docker.io/mysql:5.7.20

MAINTAINER fengjian <[email protected]>
ENV TZ "Asia/Shanghai"
ENV TERM xterm
ENV MALLOC_ARENA_MAX=1

ADD 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中

[[email protected] mysql]# cat mysql-secret.yaml 
apiVersion: v1
kind: Secret
metadata:
  name: mysql-secrets
  namespace: prodpay
#type: Opaque
data:
  root-password: QWJjZCwxMj222M0



[[email protected] 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

 

[[email protected] mysql]# cat mysql.yaml 
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: mysql
  namespace: prodpay
spec:
  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: v1
kind: Service
metadata:
  name: mysql
  namespace: prodpay
spec:
  ports:
  - name: mqsql
    port: 3306
    targetPort: 3306
  selector:
    app: mysq

 



 











以上是关于k8s mysql 单点部署的主要内容,如果未能解决你的问题,请参考以下文章

Harbor单点仓库部署

搭建K8S单点集群

聊聊如何在K8S中实现会话保持

如何访问k8s集群内部署的mysql服务

二进制部署K8s

deploy mysql operator on k8s