apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: mariadb 
  template:
    metadata:
      labels:
        component: mariadb
    spec:
      volumes:
        - name: mariadb-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
        - name: mariadb-initdb
          configMap:
            name: mariadb-initdb-config
        - name: mariadb-configmap-volume
          configMap:
            name: mariadb-configmap
      containers:
        - name: mariadb
          image: mariadb:10.4
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mariadb-storage
              mountPath: /var/lib/mysql/data
              subPath: db_data
            - name: mariadb-initdb
              mountPath: /docker-entrypoint-initdb.d
            - name: mariadb-configmap-volume
              mountPath: /etc/config
          env:
            - name: MYSQL_HOST
              value: localhost
            - name: MYSQL_ROOT_PASSWORD
              valueFrom: 
                secretKeyRef:
                  name: dbsecrets
                  key: MYSQL_ROOT_PASSWORD
            - name: MYSQL_USER
              valueFrom:
                configMapKeyRef:
                  name: mariadb-configmap
                  key: mysqluser
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: dbsecrets
                  key: MYSQL_PASSWORD
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: mariadb-configmap
                  key: mysqldatabase

