Mastodon on DigitalOcean Kubernetes
Run a decentralized social network on DigitalOcean ecosystem
3 min read
Mastodon is a self-hosted social network server based on ActivityPub. Written in Ruby, it features real-time updates, multimedia attachments, and no vendor lock-in. Mastodon is an open-source and actively developed project; thus, it is constantly improved. The main goal is to offer people more freedom and not rely on or depend on big tech companies (in contrast with what happened to Twitter lately).
From an architectural point of view, Mastodon is following a decentralized approach compared to Twitter. It means everyone can run their Mastodon instance all over the world independently and then interconnect with other mastodon instances via a federated universe(fediverse). In addition, this approach gives more freedom because you can operate alone or in small groups if desired.
At its core, Mastodon's backend is an application written using Ruby on Rails that connects with a primary PostgreSQL database. A Redis server (in-memory cache and data storage) for Mastodon's job system (Sidekiq) and an S3 storage for media file caching.
Deployment on Kubernetes
As firm believers of not re-inventing the wheel, we explored existing helm chart options to deploy Mastodon on Kubernetes and found the following,
Interestingly the official mastodon chart repository needed to be actively maintained, and they still needed an official chart release. On the other hand, Mastodon packaged by Bitnami was well documented and constantly updated. This resulted in us choosing the bitnami chart over the official chart.
Mastodon on DigitalOcean Ecosystem
Setting up the Mastodon architecture on Kubernetes is cumbersome. Moreover, achieving production readiness is all the more challenging, considering that it is a stateful application. What if we add automation into the mix? Why not? We wanted to tackle this challenge and demonstrate the simplicity of running stateful workloads at scale on the DigitalOcean ecosystem in an automated fashion.
This resulted in the inception of digitalocean/mastodon-on-kubernetes.
An open-source project that leverages modern-day best practices around infrastructure and application delivery automation to set up production-grade Mastodon instances on DigitalOcean Kubernetes. It also enables seamless integration with DigitalOcean's other product offerings, such as DBaaS and Spaces.
In the following sections, we will walk you through the steps to set up a Mastodon instance on the DigitalOcean ecosystem.
We have used Terraform to set up the following infrastructure.
DigitalOcean Kubernetes (DOKS)
- A granular setup is possible, allowing you to provision a dedicated node pool for each Mastodon backend component.
DigitalOcean managed PostgreSQL cluster
Firewall configured for enhanced security
Connection pooling is available as well via PgBouncer
High availability, replication, and automated backups
DigitalOcean Spaces (Object storage)
All the infrastructure modules can be configured based on your needs
Follow the guide» infrastructure automation for detailed instructions.
Application Delivery Automation
Bootstrap the Kubernetes cluster
We have used the continuous delivery GitOps tool ArgoCD to install and manage the essential applications
» This doc explains the bootstrap process in detail.
Deploy Bitnami Mastodon Helm Chart
Once the bootstrapped cluster is ready, we can deploy Mastodon using the helm chart. Follow the guide» mastodon installation for detailed instructions.
Monitoring and Observability
For monitoring and observability of our Kubernetes cluster, we have used Robusta, an open-source Kubernetes monitoring, troubleshooting, and automation platform which comes pre-baked with
Embedded Prometheus stack with pre-configured alerts
A web UI to see all alerts, changes, and events in your cluster
Follow the guide» set up observability for detailed instructions.
GitOps and IaC are two approaches that, when used together, create a robust end-to-end solution, as shown below.
We are eager to explore scalability using KEDA: Kubernetes Event-driven Autoscaling. Want to contribute? Feel free to check out the project.
Did you find this article valuable?
Support Abhimanyu Chitra Selvan by becoming a sponsor. Any amount is appreciated!