Services About Us Why Choose Us Our Team Development Workflow Technology Stack Case Studies Portfolio Blog Free Guides Shopify Audit ($499) Estimate Project Contact Us
Back to Insights
Ruby on Rails Sep 05, 2026 5 min read

Ruby on Rails 8 Kamal 2 Production Deployment Guide on Bare Metal & AWS

Deploying Ruby on Rails 8 with Kamal 2 to bare metal or AWS EC2 eliminates expensive PaaS margins. By pairing Kamal 2 with Docker, Traefik, and Let's Encrypt, engineering teams achieve zero-downtime rolling updates, n...

TV
TechVinta Team
Specialized in Rails, React, Marketplace & Sharetribe Flex Architecture
Verified Technical Guide

Direct Answer: Zero-Downtime Rails 8 & Kamal 2 Production Deployments

Deploying Ruby on Rails 8 with Kamal 2 to bare metal or AWS EC2 eliminates expensive PaaS margins. By pairing Kamal 2 with Docker, Traefik, and Let's Encrypt, engineering teams achieve zero-downtime rolling updates, native multi-server scaling, and direct infrastructure control for a fraction of cloud-provider fees.

The Rails 8 and Kamal 2 Architectural Paradigm Shift

For over a decade, Ruby on Rails deployment was bound to complex PaaS solutions like Heroku, container orchestrators like Kubernetes, or fragile bespoke Capistrano shell scripts. Rails 8 changes this equation natively by embracing modern deployment standards out of the box. Combined with Kamal 2—Basecamp's battle-tested deployment tool—developers can orchestrate Docker containers directly over SSH without a heavy control plane or complex orchestration overhead.

At TechVinta, our Principal Solutions Architects design high-performance bare metal and AWS infrastructures that leverage this exact stack. By bypassing managed container services, we help scaling enterprises reclaim control over their hosting spend while maintaining sub-millisecond network latencies and absolute data sovereignty.

Infrastructure Blueprint: Bare Metal vs. AWS EC2

Kamal 2 abstracts away the underlying infrastructure provider, communicating directly with target hosts via SSH and Docker. Whether you provision dedicated bare-metal servers from Hetzner or elastic EC2 instances inside an AWS VPC, the underlying deployment mechanics remain uniform, robust, and secure.

Core Infrastructure Components

  • Load Balancer & Reverse Proxy: Traefik (automatically managed via Kamal 2) handles routing, SSL termination, and zero-downtime container swapping.
  • Application Tier: Ruby on Rails 8 running inside hardened, multi-stage Docker images.
  • Database & Caching: Dedicated bare-metal instances or AWS RDS/ElastiCache clusters secured via private virtual local area networks (VLANs) or VPC peering.
  • SSL/TLS: Automated Let's Encrypt certificate issuance and renewal managed directly at the edge proxy.

Step-by-Step Production Setup & Configuration

1. Multi-Stage Dockerfile for Rails 8

Your production container must be lean, secure, and optimized for fast asset compilation and execution. Here is a production-grade Dockerfile tuned for Rails 8:


# syntax = docker/dockerfile:1
ARG RUBY_VERSION=3.3.0
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

WORKDIR /rails

RUN apt-get update -y && \
    apt-get install --no-install-recommends -y curl libjemalloc2 libsqlite3-0 libpq5 && \
    rm -rf /var/lib/apt/lists/*

ENV RAILS_ENV="production" \
    BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development:test"

FROM base AS build

RUN apt-get update -y && \
    apt-get install --no-install-recommends -y build-essential git libpq-dev pkg-config libyaml-dev && \
    rm -rf /var/lib/apt/lists/*

COPY Gemfile Gemfile.lock ./
bundle install && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/.git && \
    bundle exec bootsnap precompile --gemfile

COPY . .

RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

FROM base

COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

RUN useradd rails --create-home --shell /bin/bash && \
    chown -R rails:rails db log storage tmp
USER rails:rails

ENTRYPOINT ["/rails/bin/docker-entrypoint"]
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server"]

2. Kamal 2 Deployment Manifest (`config/deploy.yml`)

Kamal 2 uses a declarative YAML file to manage your servers, accessories (like databases or Redis), and environment secrets. Configure your production environment:


service: techvinta-core
image: your-docker-registry/techvinta-app

servers:
  web:
    hosts:
      - 192.0.2.10
      - 192.0.2.11
    options:
      restart: "always"
      labels:
        traefik.http.routers.techvinta.rule: "Host(`app.techvinta.com`)"
        traefik.http.routers.techvinta.tls: "true"
        traefik.http.routers.techvinta.tls.certresolver: "letsencrypt"

proxy:
  ssl: true
  host: app.techvinta.com
  letsencrypt:
    email: ops@techvinta.com

registry:
  username: techvinta
  password:
    - KAMAL_REGISTRY_PASSWORD

env:
  clear:
    DB_HOST: 192.0.2.20
  secret:
    - RAILS_MASTER_KEY
    - DATABASE_URL

accessories:
  db:
    image: postgres:16-alpine
    host: 192.0.2.20
    port: 5432
    env:
      clear:
        POSTGRES_DB: techvinta_production
      secret:
        - POSTGRES_PASSWORD
    volumes:
      - /var/lib/postgresql/data:/var/lib/postgresql/data

3. Executing Zero-Downtime Deployments

With your configuration in place, initializing and updating your cluster requires only simple terminal commands. Kamal handles building, pushing images, updating Traefik routing rules, and executing health checks seamlessly:


# Initial server setup and Docker installation
kamal setup

# Deploy code updates with zero downtime
kamal deploy

# Monitor cluster logs across all servers in real-time
kamal app logs -f

2026 Cost, Architecture, and Timeline Comparison

Evaluating modern infrastructure patterns requires balancing upfront engineering investment against ongoing operational expenditure. The following matrix contrasts traditional PaaS, custom Kubernetes, and a streamlined Kamal 2 deployment model.

Metric / Dimension Traditional PaaS (Heroku/Render) Managed Kubernetes (EKS/GKE) Kamal 2 + Bare Metal / AWS EC2
Monthly Infrastructure Cost $800 - $3,500+ (High markup) $1,500 - $5,000+ (Control plane fees) $150 - $600 (Raw instance cost)
Initial Setup Timeline 1 - 3 Days 3 - 6 Weeks 3 - 5 Days
Engineering Hourly Rate $35 - $65/hr (TechVinta Tier) $80 - $150/hr (K8s Specialists) $35 - $65/hr (TechVinta Tier)
Zero-Downtime Rolling Deploys Native Complex (Ingress/Service meshes) Native via Traefik & Kamal 2
Vendor Lock-In High Medium-High None (Standard Docker over SSH)

Engineering Excellence with TechVinta

Transitioning mission-critical Ruby on Rails applications to bare-metal or AWS environments requires precise architectural oversight. At TechVinta, our engineering teams maintain a 4 to 6-hour US timezone overlap, ensuring seamless real-time collaboration, rapid incident response, and transparent sprint delivery. Whether you are migrating away from prohibitive PaaS bills or architecting a multi-region scaling strategy, our seasoned Principal Architects ensure robust, secure, and cost-effective execution.

Frequently Asked Questions

How does Kamal 2 handle zero-downtime deployments without a load balancer cluster like Kubernetes?

Kamal 2 provisions and configures Traefik on each host or edge node as a lightweight reverse proxy. When a new container version is deployed, Kamal starts the new application container alongside the old one, waits for health checks to pass, and updates Traefik's routing table atomically. This guarantees zero dropped packets and uninterrupted user sessions.

Can I manage database migrations safely during a Kamal 2 deployment?

Yes. Kamal 2 automatically executes database migrations as part of the deployment lifecycle hook (invoking bin/rails db:migrate inside a temporary container or the primary app container) before routing traffic to the newly updated application nodes. For zero-downtime database updates, ensure your migrations are backward-compatible (e.g., separating column additions from code logic updates across deployments).

Is Kamal 2 suitable for high-availability multi-region setups on AWS?

Kamal 2 is exceptionally well-suited for multi-server scaling within single or multiple AWS availability zones (AZs) or bare-metal datacenters. By defining multiple target hosts in your deploy.yml manifest, Kamal coordinates deployments across geographical boundaries over secure SSH channels, making it a reliable, lightweight alternative to complex Kubernetes clusters.

Share this article:
TV

Written by TechVinta Team

We are a full-stack development agency specializing in Ruby on Rails, React.js, Vue.js, Flutter, Shopify, and Sharetribe. We write about web development, DevOps, and building scalable applications.

Keep Reading

TechVinta Assistant

Online - Ready to help

Hi there!

Need help with your project? We're online and ready to assist.

🍪

We use cookies for analytics to improve your experience. See our Cookie Policy.