apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  initContainers:
    - name: fetch
      image: andriykalashnykov/wget:1.0
      imagePullPolicy: IfNotPresent
      command:
        [
          "wget",
          "--no-check-certificate",
          "https://sample-videos.com/sql/Sample-SQL-File-1000rows.sql",
          "-O",
          "/docker-entrypoint-initdb.d/dump.sql",
        ]
      volumeMounts:
        - mountPath: /docker-entrypoint-initdb.d
          name: dump
  containers:
    - name: mysql
      image: mysql:8.0.19
      imagePullPolicy: IfNotPresent
      ports:
        - containerPort: 3306
          name: mysql
      env:
        - name: MYSQL_DATABASE
          valueFrom:
            configMapKeyRef:
              name: mysql-config
              key: MYSQL_DATABASE
        - name: MYSQL_USER
          valueFrom:
            configMapKeyRef:
              name: mysql-config
              key: MYSQL_USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secrets
              key: MYSQL_PASSWORD
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secrets
              key: MYSQL_ROOT_PASSWORD  
      resources:
        requests:
          memory: "700Mi"
          cpu: "250m"
        limits:
          memory: "700Mi"
          cpu: "550m"                           
      volumeMounts:
        - name: dump
          mountPath: /docker-entrypoint-initdb.d
        - name: config-volume ## specify volume name
          mountPath: /etc/mysql/conf.d/default_auth.cnf ## path to mount file
          subPath: default_auth ## name of config
        - name: mysql-data
          mountPath: "/var/lib/mysql"
          subPath: "mysql"                
  volumes:
    - name: dump
      emptyDir: {}
    - name: mysql-data
      persistentVolumeClaim:
        claimName: mysql-data-disk
    - name: config-volume
      configMap:
        name: mysql-config
