Mastodon on CloudFlow
Learn how to run a Mastodon server at the edge for low latency and high availability. Perform the steps below using the Kubernetes dashboard or kubectl commands.
note
Before starting, create a new CloudFlow Project and then delete the default Deployment and ingress-upstream
Service to prepare the project for your new deployment.
Prerequisites
- You need a Postgres database (try using PolyScale.ai to optimize access to a fixed-location Postgres database of your choice). See our tutorial on how PolyScale works with CloudFlow.
- Redis database (try a managed Redis, such as DigitalOcean's, or from the several listed here).
- Email delivery service or SMTP server.
- S3 bucket (try a distributed managed object store like Supabase, Backblaze, Synadia Jetstream Obj store, or Wasabi).
Deploy It
Create a CloudFlow deployment for the Mastodon server with a mastodon-deployment.yaml
file, substituting the environment variables accordingly. This will direct CloudFlow to distribute the linuxserver/mastodon
image.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mastodon
labels:
app: mastodon
spec:
replicas: 1
selector:
matchLabels:
app: mastodon
template:
metadata:
labels:
app: mastodon
spec:
containers:
- name: mastodon
image: linuxserver/mastodon:4.0.2
imagePullPolicy: Always
lifecycle:
postStart:
exec:
command:
- "/bin/sh"
- "-c"
- >
sleep 5;
sed -i -e "s/\$scheme/'https'/" /config/nginx/site-confs/default.conf
resources:
requests:
memory: "1000Mi"
cpu: "1000m"
limits:
memory: "1000Mi"
cpu: "1000m"
ports:
- containerPort: 80
readinessProbe:
httpGet:
port: 80
httpHeaders:
- name: "Host"
value: "mastodon.example.com"
failureThreshold: 15
initialDelaySeconds: 60
periodSeconds: 20
env:
- name: PUID
value: "1000"
- name: PGID
value: "1000"
- name: TZ
value: "America/New_York"
- name: LOCAL_DOMAIN
value: "mastodon.example.com"
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
- name: DB_HOST
value: "db"
- name: DB_USER
value: "mastodon"
- name: DB_NAME
value: "mastodon"
- name: DB_PASS
value: "mastodon"
- name: DB_PORT
value: "5432"
- name: SECRET_KEY_BASE
value: ""
- name: OTP_SECRET
value: ""
- name: VAPID_PRIVATE_KEY
value: ""
- name: VAPID_PUBLIC_KEY
value: ""
- name: SMTP_SERVER
value: "mail.example.com"
- name: SMTP_PORT
value: "25"
- name: SMTP_LOGIN
value: ""
- name: SMTP_PASSWORD
value: ""
- name: SMTP_FROM_ADDRESS
value: "notifications@example.com"
- name: ES_ENABLED
value: "false"
- name: ES_HOST # optional
value: "es"
- name: ES_PORT # optional
value: "9200"
- name: ES_USER # optional
value: "elastic"
- name: ES_PASS # optional
value: "elastic"
- name: S3_ENABLED
value: "false"
- name: S3_BUCKET # optional
value: ""
- name: AWS_ACCESS_KEY_ID # optional
value: ""
- name: AWS_SECRET_ACCESS_KEY # optional
value: ""
- name: S3_ALIAS_HOST # optional
value: ""
- name: WEB_DOMAIN # optional
value: "mastodon.example.com"
Apply this deployment resource to your Project with either the Kubernetes dashboard or kubectl apply -f mastodon-deployment.yaml
.
tip
For a production Mastodon server, use Kubernetes Secrets as the values for private environment variables.
Expose It
Expose it on the internet, mapping the container's port 80
.
apiVersion: v1
kind: Service
metadata:
labels:
app: ingress-upstream
name: ingress-upstream
spec:
ports:
- name: 80-8080
port: 80
protocol: TCP
targetPort: 80
selector:
app: mastodon
sessionAffinity: None
type: ClusterIP
Apply this service resource to your Project with either the Kubernetes dashboard or kubectl apply -f ingress-upstream.yaml
.
See the pods running on CloudFlow's network with either the Kubernetes dashboard or kubectl get pods -o wide
. The -o wide
switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.
Finally, follow the instructions that configure DNS and TLS.
See What You've Built
See the Mastodon server you've built by visiting the https://mastodon.example.com
, substituting mastodon.example.com
according to your DNS and HTTPS configuration.