apiVersion: v1
kind: Service
metadata:
  name: mattermost-mariadb
  namespace: mattermost
  labels:
    app: mattermost
spec:
  ports:
    - name: mariadb
      port: 3306
      targetPort: mariadb
  selector:
    app: mattermost
    tier: mariadb
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-mm-pv-claim
  namespace: mattermost
  labels:
    app: mattermost
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost-mariadb
  namespace: mattermost
  labels:
    app: mattermost
spec:
  selector:
    matchLabels:
      app: mattermost
      tier: mariadb
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mattermost
        tier: mariadb
    spec:
      containers:
      - image: docker-registry:32000/mariadb:1.0
        name: mariadb
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: ROOT_PASSWORD
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: DATABASE
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: PASSWORD
        ports:
        - containerPort: 3306
          name: mariadb
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      imagePullSecrets:
      - name: reg-cred-secret    
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-mm-pv-claim
