How to Self-Host a Mastodon Instance in Kubernetes


TL;DR: Instead of the official installation including setting up Ruby, nginx, systemd service, etc., I found it more comfortable to install and run a Mastodon instance using some YAML files.

Just in case, what is Mastodon anyway?

I used kustomize to manage and generate Kubernetes manifests for a fully functional Mastodon instance. Please see my kustomize base templates, and then my awes.one overrides to get an idea. The secret mastodon with some credentials aren’t there of course but it looks like:

apiVersion: v1
kind: Secret
metadata:
  name: mastodon
type: Opaque
stringData:
  # postgres
  DB_HOST: 192.168.1.100
  DB_NAME: mastodon
  DB_PASS: changeme
  DB_PORT: 5432
  DB_USER: mastodon
  # elasticsearch
  ES_ENABLED: "true"
  ES_HOST: 192.168.1.101
  ES_PORT: 9200
  # domain name
  LOCAL_DOMAIN: my-mastodon-domain.com
  # redis service name
  REDIS_HOST: mastodon-redis
  REDIS_PORT: 6379
  # email 
  SMTP_FROM_ADDRESS: [email protected]
  SMTP_PORT: 25
  SMTP_SERVER: 192.168.1.102
  # secrets
  OTP_SECRET: generate-yours
  SECRET_KEY_BASE: generate-yours
  VAPID_PRIVATE_KEY: generate-yours
  VAPID_PUBLIC_KEY: generate-yours

Please see this on how to generate application secrets used above. Also, I couldn’t be bothered with writing the typical setup for postgres and elasticsearch.

Please feel free to message me @raynix once your Mastodon instance is up and running 🙂

,