apiVersion: apps/v1
kind: Deployment
metadata:
    name: mattermost
    labels:
        app: mattermost
spec:
    replicas: 1
    selector:
        matchLabels:
            app: mattermost
    template:
        metadata:
            labels:
                app: mattermost
        spec:
#            securityContext:
#                runAsUser: 1000
#                fsGroup: 1000
            containers:
                - image: k8spracticalguide/mattermost:4.10.2
                  name: mattermost
                  securityContext:
                      allowPrivilegeEscalation: false
                  env:
                      - name: MM_USERNAME
                        valueFrom:
                            configMapKeyRef:
                                name: common-env
                                key: MYSQL_USER
                      - name: MM_PASSWORD
                        valueFrom:
                            secretKeyRef:
                                name: common-env
                                key: MYSQL_PASSWORD
                      - name: DB_NAME
                        valueFrom:
                            configMapKeyRef:
                                name: common-env
                                key: MYSQL_DATABASE
                      - name: DB_HOST
                        value: mysql-0.mysql
                      - name: DB_PORT_NUMBER
                        value: "3306"
                      - name: MM_SQLSETTINGS_DRIVERNAME
                        value: mysql
                      - name: MM_SQLSETTINGS_DATASOURCE
                        value: $(MM_USERNAME):$(MM_PASSWORD)@tcp(mysql-0.mysql:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s
                  ports:
                      - containerPort: 8065
                  volumeMounts:
                      - name: cm-volume
                        mountPath: /mm/config
                  livenessProbe:
                      initialDelaySeconds: 90
                      timeoutSeconds: 5
                      periodSeconds: 15
                      httpGet:
                          path: /api/v4/system/ping
                          port: 8065
                  readinessProbe:
                      initialDelaySeconds: 15
                      timeoutSeconds: 5
                      periodSeconds: 15
                      httpGet:
                          path: /api/v4/system/ping
                          port: 8065
                  lifecycle:
                      preStop:
                          exec:
                              command:
                              - sleep
                              - 5s
                  resources:
                      requests:
                          cpu: 100m
                          memory: 100Mi
            volumes:
                - name: cm-volume
                  configMap:
                      name: mm-config-file
                      items:
                          - key: config.json
                            path: config.json

