Mastodon Hosting on Akash Network: Deploy in Minutes for Less Than $10/mo

By March 13, 2023Akash

Why Akash?

This comprehensive guide will show you how to unlock the full potential of hosting Mastodon on Akash. Mastodon is an open-source social network platform that provides a powerful and secure way to communicate and collaborate with others. Akash is a decentralized cloud computing platform that allows users to deploy and manage distributed applications and services. By combining these two powerful technologies, you can benefit from a reliable, secure, and cost-effective hosting solution. This guide will provide you with the necessary information to get started and maximize the benefits of hosting Mastodon on Akash.

Requirements:

Setup Overview:

  1. Create secrets/keys locally and configure Mailjet for a domain/email.
  2. Update required variables in YAML
  3. Deploy in Cloudmos

On your local machine

We need to first create secrets and vapid keys before deploying. Start by copy and pasting the YAML below into your favorite text editor. We need to update the variables.

To create secrets you need to run a Dockerfile locally:

docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-secret

Create 3 secrets and fill in PASSWORD=, SECRET_KEY_BASE=, and OTP_SECRET=

Now, for Vapid Keys Run

docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-vapid

and fill in VAPID_PRIVATE_KEY= and VAPID_PUBLIC_KEY= with the values.

Mailjet

You need to setup a free Mailjet account to enable the SMTP server as configured below. Once you account is created, add a domain and verify it. Then get your API key credentials and update them in the YAML as required. You cannot register/verify a user without a working SMTP server! Update SMTP_FROM_ADDRESS=, SMTP_LOGIN=, and SMTP_PASSWORD=.

Cloudmos Deploy

Create Deployment

Using Cloudmos Deploy create a new blank deployment and copy and paste the YAML with the updated variables into the online editor.

First Run

When you run the app for the first time, it will create the databases and start the web server. However, a configuration change is needed, and it may take up to three minutes for the process to complete. Please be patient and let the process finish. If you click on the URI at this point you will see in the logs :

mastodon: [ActionDispatch::HostAuthorization::DefaultResponseApp] Blocked host: o0ido8nb6lc8v04816ipu8vhss.ingress.america.computer 

Go to Cloudmos Deploy and find the deployment URI. This URI will be used to update the LOCAL_DOMAIN= and WEB_DOMAIN= environmental variables.

Edit the deployment YAML and locate the LOCAL_DOMAIN= and WEB_DOMAIN= environmental variables.

Update these variables with the full URI you copied from Cloudmos Deploy.

Click on “Update” to apply the changes to your deployment. Wait for the pod to be restarted. This may take a couple of minutes, so please be patient. Once the pod is restarted, try to access the URI. You may see an HTTPS warning, but it is safe to ignore it and proceed to the app. Finally, configure your DNS settings to point your domain to the URI.

version: "2.0"

services:
  mastodon:
    image: linuxserver/mastodon
    expose:
      - port: 443
        as: 443
        to:
          - global: true
      - port: 80
        as: 80
        to:
          - global: true
    env:
      - PUID=1000
      - PGID=1000
      - AWS_ACCESS_KEY_ID=
      - AWS_SECRET_ACCESS_KEY=
      - DB_HOST=db
      - DB_NAME=mastodon
      - DB_PASS=mastodon
      - DB_POOL=5
      - DB_PORT=5432
      - DB_USER=mastodon
      - ES_ENABLED=false
      - ES_HOST=es
      - ES_PASS=elastic
      - ES_PORT=9200
      - ES_USER=elastic
      - PASSWORD="" #Generated from (docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-secret)
      - LOCAL_DOMAIN= #Full URI used after deployment
      - OTP_SECRET="" #Generated from (docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-secret)
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - S3_ALIAS_HOST=
      - S3_BUCKET=
      - S3_ENABLED=false
      - SECRET_KEY_BASE=
      - SIDEKIQ_DEFAULT=false
      - SIDEKIQ_ONLY=false
      - SIDEKIQ_QUEUE=
      - SIDEKIQ_THREADS=5
      - SMTP_FROM_ADDRESS=mastodon@test.com #Signup for mailjet.com and setup email
      - SMTP_LOGIN= #mailjet API key
      - SMTP_PASSWORD= #mailjet secret 
      - SMTP_PORT=25
      - SMTP_SERVER=in-v3.mailjet.com
      - TZ=Etc/UTC
      - VAPID_PRIVATE_KEY="" #Generated from auth container (docker run --rm -it --entrypoint /bin/bash lscr.io/linuxserver/mastodon generate-vapid)
      - VAPID_PUBLIC_KEY="" #Generated from auth container command
      - WEB_DOMAIN= #Full URI used after deployment
    depends_on:
      - db
      - redis
  redis:
    image: redis:7-alpine
    expose:
      - port: 6379
        proto: tcp
        to:
          - service: mastodon
  db:
    image: postgres:14-alpine
    expose:
      - port: 5432
        proto: tcp
        to:
          - service: mastodon
    env:
      - POSTGRES_HOST_AUTH_METHOD=trust
      - POSTGRES_PASSWORD=mastodon
      - POSTGRES_DB=mastodon
      - POSTGRES_USER=mastodon
profiles:
  compute:
    mastodon:
      resources:
        cpu:
          units: 4.0
        memory:
          size: 2.5Gi
        storage:
          size: 16Gi
    redis:
      resources:
        cpu:
          units: 1
        memory:
          size: 1Gi
        storage:
          - size: 1Gi
    db:
      resources:
        cpu:
          units: 1
        memory:
          size: 1Gi
        storage:
          - size: 1Gi

  placement:
    akash:
      attributes:
        host: akash
      signedBy:
        anyOf:
          - "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63"
          - "akash18qa2a2ltfyvkyj0ggj3hkvuj6twzyumuaru9s4"
      pricing:
        mastodon:
          denom: uakt
          amount: 100000
        redis:
          denom: uakt
          amount: 1000
        db:
          denom: uakt
          amount: 1000

deployment:
  mastodon:
    akash:
      profile: mastodon
      count: 1
  redis:
    akash:
      profile: redis
      count: 1
  db:
    akash:
      profile: db
      count: 1      

Extra Resources

https://hub.docker.com/r/linuxserver/mastodon

Leave a Reply