apiVersion: v1
kind: Secret
metadata:
  name: mysql-credentials
  namespace: apps
type: Opaque
stringData:
  MYSQL_ROOT_PASSWORD: "2f00684665be1c504d65ee21956573b2"
  MYSQL_USER: app
  MYSQL_PASSWORD: "2f00684665be1c504d65ee21956573b2"
  MYSQL_DATABASE: db_bookstack
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-initdb
  namespace: apps
data:
  init.sql: |
    FLUSH PRIVILEGES;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-data
  namespace: apps
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: apps
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mariadb:11
          ports:
            - containerPort: 3306
          envFrom:
            - secretRef:
                name: mysql-credentials
          resources:
            requests:
              cpu: 50m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 256Mi
          volumeMounts:
            - name: mysqldata
              mountPath: /var/lib/mysql
            - name: initdb
              mountPath: /docker-entrypoint-initdb.d
      volumes:
        - name: mysqldata
          persistentVolumeClaim:
            claimName: mysql-data
        - name: initdb
          configMap:
            name: mysql-initdb
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: apps
spec:
  selector:
    app: mysql
  ports:
    - port: 3306
      targetPort: 3306
