apiVersion: apps/v1
kind: Deployment

metadata:
  namespace: singouins-dev
  name: sep-backend-mariadb
  labels:
    tier: sep-backend
spec:
  selector:
    matchLabels:
      app: mariadb
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9104"
        prometheus.io/path: "/metrics"
      labels:
        app: mariadb
        tier: sep-backend
    spec:

      containers:
        - image: mariadb:10.4
          name: sep-backend-mariadb
          resources:
            limits:
              memory: 512Mi
              cpu: 200m
            requests:
              memory: 256Mi
              cpu: 100m
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: sep-backend-mariadb-secret
                  key: mariadb-pass
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: db
              mountPath: /var/lib/mysql
            - name: config
              mountPath: /etc/mysql/mariadb.conf.d
        - name: mariadb-exporter
          image: prom/mysqld-exporter
          resources:
            limits:
              memory: 32Mi
              cpu: 50m
            requests:
              memory: 16Mi
              cpu: 10m
          env:
            - name: DATA_SOURCE_NAME
              valueFrom:
                secretKeyRef:
                  name: sep-backend-mariadb-secret
                  key: exporter-dsn
          ports:
          - containerPort: 9104

      volumes:
        - name: db
          persistentVolumeClaim:
            claimName: sep-backend-mariadb-db
        - name: config
          configMap:
            name: sep-backend-mariadb
            items:
              - key: config
                path: custom.cnf
