apiVersion: v1
kind: Namespace
metadata:
  name: mattermost
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost
  namespace: mattermost
  labels:
    app: mattermost
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mattermost
  template:
    metadata:
      labels:
        app: mattermost
    spec:
      containers:
      - name: mattermost
        image: allardkrings/mattermost
        env:
        - name: DB_PORT_NUMBER
          value: "3306"
        - name: MM_SQLSETTINGS_DRIVERNAME
          value: "mysql"
        - name: MM_SQLSETTINGS_DATASOURCE
          value: "mattermost:mattermost@tcp(mariadb.mariadb.svc.cluster.local:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
        - name: MM_USERNAME
          value: "mattermost"
        - name: MM_PASSWORD
          value: "mattermost"
        - name: MM_DBNAME
          value: "mattermost"
        - name: DOMAIN
          value: "mattermost-prod.allarddcs.nl"
        - name: MM_SERVICESETTINGS_SITEURL
          value: "https://mattermost-prod.allarddcs.nl"
        - name: PMA_HOST
          value: mariadb.mariadb.svc.cluster.local
        - name: PMA_PORT
          value: "3306"
        - name: MYSQL_ROOT_PASSWORD
          value: "zabbix"
        - name: TZ
          value: "UTZ"
        volumeMounts:
        - mountPath: /mattermost/config
          name: mattermost
        - mountPath: /mattermost/data
          name: mattermost
        - mountPath: /mattermost/logs
          name: mattermost
        - mountPath: /mattermost/plugins
          name: mattermost
      volumes:
      - name: mattermost
        persistentVolumeClaim:
          claimName: mattermost-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: mattermost
  namespace: mattermost
spec:
  ports:
  - name: http
    targetPort: 8065
    port: 8065
  selector:
    app: mattermost
  type: ClusterIP
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: mattermost-http
  namespace: mattermost
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`mattermost-prod.allarddcs.nl`)
    kind: Rule
    services:
    - name: mattermost
      port: 8065
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: mattermost-tls
  namespace: mattermost
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`mattermost-prod.allarddcs.nl`)
    kind: Rule
    services:
    - name: mattermost
      port: 8065
  tls:
    certResolver: letsencrypt
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mattermost-pv
spec:
  storageClassName: ""
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/mattermost
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mattermost-pvc
  namespace: mattermost
spec:
  storageClassName: ""
  volumeName: mattermost-pv
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi

