成功最有效的方法就是向有经验的人学习!

快速部署mysql 5.7单机版

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-sre
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "640Gi"
  volumeName: 
  storageClassName: nfs
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-config-sre
data:
  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
        bind-address   = 0.0.0.0
        # Disabling symbolic-links is recommended to prevent assorted security risks
        symbolic-links=0
        max_connections=1000
        default_storage_engine=innodb
        skip_external_locking
        lower_case_table_names=1
        skip_host_cache
        skip_name_resolve
        character_set_server=utf8
        sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-sre-database
  labels:
    app: mysql-sre
spec:
  selector:
    matchLabels:
      app: mysql-sre
  template:
    metadata:
      labels:
        app: mysql-sre
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        imagePullPolicy: IfNotPresent
        args:
        - --default_authentication_plugin=mysql_native_password
        - --character-set-server=utf8mb4
        - --collation-server=utf8mb4_unicode_ci
        ports:
        - containerPort: 3306
          name: dbport
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: 1111111111111111
        - name: MYSQL_DATABASE
          value: wordpress
        - name: MYSQL_USER
          value: wordpress
        - name: MYSQL_PASSWORD
          value: wordpress
        volumeMounts:
        - name: db-data
          mountPath: /var/lib/mysql
        - name: mysql-config
          mountPath: /etc/mysql/conf.d/  
      volumes:
      - name: db-data
        persistentVolumeClaim:
          claimName: mysql-sre
      - name: mysql-config
        configMap:
          name: mysql-config-sre  
apiVersion: v1
kind: Service
metadata:
  name: mysql-sre
spec:
  type: NodePort
  ports:
  - name: mysqlport
    protocol: TCP
    port: 3306
    targetPort: dbport
    nodePort: 30106
  selector:
    app: mysql-sre
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-sre-backup
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "640Gi"
  volumeName: 
  storageClassName: nfs
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: mysql-sre-backup
spec:
  schedule: "0 2 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: mysql-backup
            imagePullPolicy: IfNotPresent
            image: mysql:5.7
            env:
            - name: MYSQL_BACKUP_USER
              value: root
            - name: MYSQL_BACKUP_USER_PASSWORD
              value: rootPassW0rd
            - name: MYSQL_HOST
              value: mysql-sre
            command:
            - /bin/sh
            - -c
            - |
              set -ex
              mysqldump --host=MYSQL_HOST --user=MYSQL_BACKUP_USER \
                        --password=$MYSQL_BACKUP_USER_PASSWORD \
                        --routines --databases appdb --single-transaction \
                        > /mysql-backup/mysql-`date +"%Y%m%d"`.sql
            volumeMounts:
            - name: mysql-backup
              mountPath: /mysql-backup
          restartPolicy: OnFailure
          volumes:
          - name: mysql-backup
            persistentVolumeClaim:
              claimName: mysql-sre-backup
赞(0) 打赏
未经允许不得转载:竹影清风阁 » 快速部署mysql 5.7单机版
分享到

大佬们的评论 抢沙发

全新“一站式”建站,高质量、高售后的一条龙服务

微信 抖音 支付宝 百度 头条 快手全平台打通信息流

橙子建站.极速智能建站8折购买虚拟主机

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册