1. Home
  2. Docs
  3. Infrastructure
  4. Mautic (Engineering)
  5. Installing Mautic in Kubernetes

Installing Mautic in Kubernetes

References:

Overall Steps

  1. In AWS RDS MariaDB, Create Database & User
  2. Install Mautic Deployment
  3. Configure CNAME record in CloudFlare DNS
  4. Configure nginx-ingress
  5. Mautic Setup Wizard
  6. Configure AWS SES SMTP
  7. Automatic backups

Installation Details

Inspired by https://github.com/nickwild-999/mautic-kubernetes/blob/master/mautic.yml

Mautic Docker image: https://hub.docker.com/r/mautic/mautic/

  • MAUTIC_DB_HOST=(secret)
  • MAUTIC_DB_USER=mautic
  • MAUTIC_DB_PASSWORD=(secret)
  • MAUTIC_DB_NAME=mautic
  • MAUTIC_TRUSTED_PROXIES=10.0.0.0/8

Secret: lovia-prod-mautic

  • db-host
  • db-password
kubectl create secret generic lovia-prod-mautic --from-literal=db-host=CHANGEME.ap-southeast-1.rds.amazonaws.com:3306 --from-literal=db-password='CHANGEME'

Create database:

CREATE DATABASE mautic CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER [email protected]'%' IDENTIFIED BY '************';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON mautic.* TO [email protected]'%';
FLUSH PRIVILEGES;

You’ll need to create a Persistent Volume Claim (PVC). This is mounted as /var/www/html, and contains user data: plugins, themes, and media. mautic-pvc.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mautic-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: do-block-storage

mautic.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mautic 
  labels:
    app: mautic 
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mautic 
  template:
    metadata:
      labels:
        app: mautic 
    spec:
      containers:
        - image: mautic/mautic 
          name: mautic
          env:
          - name: MAUTIC_DB_HOST
            value: *.ap-southeast-1.rds.amazonaws.com:3306
          - name: MAUTIC_DB_USER
            value: mautic
          - name: MAUTIC_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: lovia-prod-mautic
                key: db-password
          - name: MAUTIC_DB_NAME
            value: mautic
          - name: MAUTIC_RUN_CRON_JOBS
            value: 'true'
          - name: MAUTIC_TRUSTED_PROXIES
            # value: nginx-ingress-controller.default.svc.cluster.local
            value: 10.0.0.0/8
          ports:
            - containerPort: 80
              name: mautic
          volumeMounts:
          - mountPath: "/var/www/html"
            name: mautic-var-www-html
          # Health check
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            httpGet:
              path: /s/login
              port: 80
          resources:
            limits:
              memory: 384Mi
            requests:
              memory: 384Mi
      volumes:
        - name: mautic-var-www-html
          persistentVolumeClaim:
            claimName: mautic-pvc

mautic-service.yaml:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mautic 
  name: mautic 
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: mautic 

Apply:

kubectl apply -f mautic-pvc.yaml
kubectl apply -f mautic.yaml
kubectl apply -f mautic-service.yaml

Add CNAME record mautic.lovia.life to k8s-lovia-sg.lovia.life.

Create Ingress for Mautic, with LetsEncrypt SSL support: mautic-ingress.yaml:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: mautic-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    # https://github.com/nginxinc/kubernetes-ingress/issues/21#issuecomment-521338887
    nginx.ingress.kubernetes.io/proxy-body-size: 64m
    # https://discuss.erpnext.com/t/erpnext-ssl-https-config-not-working-with-nginx/11314 (default is 60)
    nginx.ingress.kubernetes.io/proxy-read-timeout: '120'
    # https://pumpingco.de/blog/using-signalr-in-kubernetes-behind-nginx-ingress/
    nginx.ingress.kubernetes.io/affinity: cookie
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  # REQUIRES helm cert-manager
  tls:
    - hosts:
        - mautic.lovia.life
      secretName: mautic-tls
  rules:
    - host: mautic.lovia.life
      http:
        paths:
          - backend:
              serviceName: mautic
              servicePort: 80

Apply the ingress:

kubectl apply -f mautic-ingress.yaml

Go to https://mautic.lovia.life/installer

Was this article helpful to you? Yes No 1

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *