Ghost Blog - SMTP environment variables with Docker/Kubernetes

There is not much resources out there on how to setup a self hosted Ghost blog using Kubernetes and especially how to setup a Mailgun SMTP user.

Kubernetes

To see how to host Ghost blog with kubernetes check out this article: https://igor.technology/installing-ghost-on-digitalocean-with-kubernetes/

Here is simple deploymeny descriptor for Kubernetes with added Mailgun environment variables settings:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: blog
  labels:
    app: blog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blog
  template:
    metadata:
      labels:
        app: blog
    spec:
      containers:
      - name: blog
        image: ghost:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 2368
        env:
        - name: url
          value: https://igor.technology
        - name: mail__transport
          value: "SMTP"
        - name: mail__from
          value: "My name <postmaster@mydomain.com>"
        - name: mail__options__service
          value: "Mailgun"
        - name: mail__options__auth__user
          value: postmaster@mydomain.com
        - name: mail__options__auth__pass
          value: smtpmailgunpassword
        volumeMounts:
          - mountPath: /var/lib/ghost/content
            name: content
      volumes:
      - name: content
        persistentVolumeClaim:
          claimName: blog-content
deployment.yaml

Update the deployment descriptor by running: kubectl apply -f deployment.yaml

Docker

Running docker instance uses exact same environement variables as Kuberentes. here is an example:

docker run -d \
-p 3001:2368 \
-v /mylocalfolder/ghost/content:/var/lib/ghost/content \
-e mail__transport="SMTP" \
-e mail__from="Sample <sample@example.com>" \
-e mail__options__service="SMTP" \
-e mail__options__host="smtp.sendgrid.net" \
-e mail__options__port="587" \
-e mail__options__auth__user="username" \
-e mail__options__auth__pass="password" \
ghost