Kubernetes is powerful. But for most Rails projects, it is also an overcomplicated machine that is expensive and hard to maintain. Since version 2, Kamal has established itself as the serious alternative: a minimalist, open source deployment tool designed for teams that want to ship fast without sacrificing reliability. Built on Docker and SSH, Kamal 2 manages the full lifecycle of your containers directly on your servers. Zero unnecessary abstraction, zero vendor lock-in. In this guide, we will see how to configure Kamal 2 from A to Z to deploy a Ruby on Rails application to production, with a built-in load balancer, secrets management and automatic rollback. Whether you are a solo developer or the tech lead of a startup, this guide gives you everything you need to control your infrastructure without depending on a third-party platform.
Kamal 2: what exactly is it?
Kamal 2 is an open source deployment tool developed by 37signals, the company behind Ruby on Rails and Basecamp. It is designed to deploy containerized applications on bare metal servers or VPS over SSH and Docker.
A practical answer to Kubernetes complexity
Kubernetes requires sharp DevOps expertise and dedicated infrastructure. For a startup or an SME, the human and technical cost is rarely justified. Kamal 2 solves this problem by offering robust deployment with a very gentle learning curve.
What Kamal 2 delivers in practice
- Zero-downtime deployments thanks to the Kamal Proxy load balancer (built in since v2).
- Encrypted secrets management with Kamal Secrets, compatible with dotenv and 1Password.
- Instant rollback to the previous Docker image in one command.
- Multi-server: deploy to 1 or 50 servers with the same configuration.
- Docker accessories: database, Redis and Sidekiq managed natively.
Kamal Proxy: the replacement for Traefik
Kamal 2 drops Traefik in favor of Kamal Proxy, an ultra-light in-house reverse proxy. It automatically handles SSL via Let's Encrypt and keeps traffic flowing without interruption during deployments.
“Kamal 2 gives you the power of a professional deployment without the complexity of an orchestration platform. It is DevOps for developers.”
Technical prerequisites
Before you start, you will need:
- A Linux VPS (Ubuntu 22.04 LTS recommended) with root SSH access.
- Docker installed on the server (Kamal installs it automatically if it is missing).
- A Docker registry: Docker Hub, GitHub Container Registry or GitLab Registry.
- Ruby 3.2+ and Rails 7.1+ on your local machine.
Configuring Kamal 2 for a Rails app
Kamal 2 configuration relies on two main files: config/deploy.yml and .kamal/secrets. Here is how to structure them correctly for a Rails app in production.
Installing Kamal 2
Kamal is installed as a Ruby gem. Add it to your Gemfile or install it globally:
With gem install kamal, the kamal command is available globally. Rails 7.2+ includes Kamal by default in the generated Gemfile. Then run kamal init to create the configuration structure.
Structure of the deploy.yml file
The config/deploy.yml file is the heart of your configuration. It defines:
- service: the name of your application.
- image: the Docker image on your registry.
- servers: the list of your servers' IP addresses.
- proxy: the SSL configuration and the domain.
- accessories: the supporting services (PostgreSQL, Redis).
Minimal example for a Rails app with PostgreSQL:
The proxy.ssl: true field automatically enables Let's Encrypt. Kamal handles certificate renewal with no manual intervention.
Managing secrets with Kamal Secrets
Since Kamal 2, secrets are stored in .kamal/secrets (gitignored by default). You can source them from the local environment, a dotenv file, or directly from 1Password.
“Never store your API keys or DATABASE_URL in plain text in deploy.yml. Always use Kamal Secrets or encrypted environment variables.”
Configuring the Rails Dockerfile
Rails 7.2+ generates a Dockerfile optimized for production. A few recommended adjustments:
- Multi-stage build: separate the assets stage from the runtime stage.
- Non-root user: create a dedicated user for security.
- ENTRYPOINT: use the
./bin/docker-entrypointgenerated by Rails.
Deploying to production with Kamal 2
Once the configuration is in place, deployment takes a single command: kamal setup for the first deployment, then kamal deploy for the following ones.
First deployment: kamal setup
kamal setup performs, in order:
- Installing Docker on the server if it is missing.
- Starting Kamal Proxy as a Docker container.
- Pushing the image to the registry from your local machine.
- Starting the accessories (database, Redis).
- Launching the app and running the Rails migrations.
Subsequent deployments: kamal deploy
Subsequent deployments use kamal deploy. Kamal builds the Docker image, pushes it to the registry, then performs a zero-downtime rolling update on your servers. Traffic switches instantly to the new version once the health checks pass.
Rollback and incident management
If something goes wrong, kamal rollback restores the previous image in under 30 seconds. You can also use:
kamal app logs: access to logs in real time.kamal app exec: run a command in a production container.kamal app restart: restart the app without a rebuild.
Multi-environment deployments
Kamal 2 supports multiple destinations via the --destination flag. Create a config/deploy.staging.yml file for your staging environment. The kamal deploy --destination staging command deploys to your staging servers with the dedicated configuration.
Kamal 2 vs Kubernetes: which tool should you choose?
The choice between Kamal 2 and Kubernetes depends on the size of your team, your application load and your DevOps budget. Here is an objective comparison.
| Criterion | Kamal 2 | Kubernetes |
|---|---|---|
| Learning curve | Low (1-2 days) | High (several weeks) |
| Infrastructure required | 1 VPS is enough | Cluster of at least 3 nodes |
| Monthly cost | From €5/month (Hetzner) | €200+ (managed cluster) |
| Zero-downtime | Yes (Kamal Proxy) | Yes (rolling updates) |
| Auto-scaling | No (manual) | Yes (HPA) |
| Rollback | In 30 seconds | In 1-5 minutes |
| Automatic SSL | Yes (Let's Encrypt) | Via cert-manager |
| Dedicated DevOps team | Not needed | Essential |
When to choose Kamal 2
Kamal 2 is the ideal choice for:
- Startups and SMEs that want simple infrastructure they control.
- Rails teams without a dedicated DevOps engineer.
- Apps with predictable traffic and no need for aggressive auto-scaling.
- Projects with a limited infrastructure budget (Hetzner VPS at €5-20/month).
When Kubernetes is still relevant
Kubernetes keeps the edge for complex microservices architectures with hundreds of services, a need for dynamic auto-scaling and dedicated DevOps teams. For 95% of Rails apps in production, Kamal 2 is more than enough.
The real cost of infrastructure
A managed Kubernetes cluster (GKE, EKS, AKS) costs on average €300 to €800/month for a medium-traffic app. With Kamal 2 on a Hetzner CX31 VPS (€12/month), you get 4 vCPU, 8 GB of RAM and enough performance to serve thousands of concurrent users.
Best practices and advanced use cases
Mastering Kamal 2 is not just about running kamal deploy. Here are the practices that make the difference between a fragile deployment and production-ready infrastructure.
Automating deployment with GitHub Actions
Integrate Kamal 2 into your CI/CD pipeline with GitHub Actions. Create a workflow that automatically triggers kamal deploy after a push to the main branch. Store your secrets (SSH key, registry token) in your repository's GitHub Secrets.
Monitoring your app in production
Kamal does not provide native monitoring. Combine it with:
- Sentry: for real-time Rails error tracking.
- Uptime Robot: for availability alerts (free up to 50 monitors).
- Grafana + Prometheus: for advanced system metrics.
- Logflare or Papertrail: for log centralization.
Automatic backups with an accessory
Declare a Kamal accessory dedicated to PostgreSQL backups. Use pg_dump in a container scheduled via cron. Send the encrypted dumps to an S3 or Backblaze B2 bucket. A good backup is the first line of defense for your production. Monitoring, tested backups and updates are the core of serious Ruby on Rails application maintenance.
“A deployment without automated backups is not a production deployment. It is a game of chance.”
Horizontal scaling with Kamal 2
Kamal 2 supports manual horizontal scaling. Simply add new servers to your servers list and run kamal deploy again. Kamal Proxy automatically distributes traffic across all configured servers. To go further in mastering your Rails stack, read our guide Ruby on Rails 2026: the pro guide to shipping fast. Our Ruby on Rails agency configures and manages Kamal 2 infrastructure in production for you. If you want to assess the cost of a rebuild or a new project, our article on Ruby on Rails development prices in 2026 will give you concrete benchmarks. Finally, do not forget that your app's visibility also depends on SEO: read our guide to SEO rank tracking to steer your rankings.
FAQ
Does Kamal 2 work with every VPS host?
Yes. Kamal 2 works with any VPS reachable over SSH running Ubuntu 20.04+ or Debian 11+. The most widely used hosts are Hetzner, DigitalOcean, OVH and Scaleway.
Hetzner is particularly recommended for its excellent value for money. A CX31 server at €12/month is enough for most Rails applications in production.
Can you use Kamal 2 without Docker Hub?
Yes. Kamal 2 is compatible with every Docker registry that complies with the OCI standard. You can use GitHub Container Registry (GHCR), GitLab Registry or your own private registry.
GHCR is free for public repositories and offers 500 MB of free storage for private repos. It is often the best choice for teams already on GitHub.
Does Kamal 2 handle database migrations automatically?
Yes. You can configure migrations in the boot.cmd section or through a pre-deploy hook in your Kamal configuration. Rails then runs rails db:migrate before each deployment.
Be careful: plan backward-compatible migrations to avoid errors during zero-downtime deployment. The expand-and-contract strategy is recommended.
What is the difference between Kamal 1 and Kamal 2?
Kamal 2 (released in late 2024) brings three major changes: the replacement of Traefik with Kamal Proxy (simpler, faster), the overhaul of secrets management with Kamal Secrets, and better handling of Docker accessories.
Kamal 2 also simplifies the configuration of multi-arch builds and improves deployment performance on large server fleets. The migration from Kamal 1 is documented and generally takes less than an hour.
Do you need a DevOps expert to use Kamal 2 in production?
No. That is precisely the goal of Kamal: to let a Rails developer deploy to production without advanced DevOps expertise. The initial configuration takes 1 to 2 hours for a developer who is new to the tool.
For companies that want to outsource this setup, the Akolads teams can support you from the initial configuration through to ongoing operational maintenance. Contact us to discuss it.