Skip to content

Latest commit

 

History

History
133 lines (119 loc) · 2.23 KB

常用服务部署.md

File metadata and controls

133 lines (119 loc) · 2.23 KB

一、单机 MySQL8

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql8-pv
  namespace: database
spec:
  capacity:
    storage: 50Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  storageClassName: nfs-client 
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /app/nfs/
    server: 192.168.1.122
    
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql8-pvc
  namespace: database
spec:
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  storageClassName: nfs-client 
  resources:
    requests:
      storage: 50Gi

--- 
kind: ConfigMap
apiVersion: v1
metadata:
  name: mysql8-config
  namespace: database
data:
  my.cnf: |-
    [mysql]
    default-character-set=utf8

    [client]
    default-character-set=utf8

    [mysqld]
    # 字符集
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    # 最大连接数
    max_connections=1000
    # binlog
    log-bin=mysql-bin
    binlog-format=ROW
    # 忽略大小写
    lower_case_table_names=2

---
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql8
  namespace: database
spec:
  selector:
    matchLabels:
      app: mysql8
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql8
    spec:
      containers:
      - image: mysql:8
        name: mysql8
        volumeMounts:
        - name: time-zone
          mountPath: /etc/localtime
        - name: mysql8-persistent-storage
          mountPath: /var/lib/mysql
        - name: config
          mountPath: /etc/mysql/conf.d
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"  # change: Ioubuy123
        ports:
        - containerPort: 3306
          name: mysql8
      volumes:
        - name: mysql8-persistent-storage
          persistentVolumeClaim:
            claimName: mysql8-pvc
        - name: time-zone
          hostPath: 
            path: /etc/localtime
        - name: config
          configMap:
            name: mysql8-config

---
apiVersion: v1
kind: Service
metadata:
  name: mysql8-svc
  namespace: database
spec:
  selector:
    app: mysql8
  type: NodePort
  ports:
  - name: mysql8-svc
    protocol: TCP
    port: 3306
    targetPort: 3306
    nodePort: 31236