Configuration

Roles

Different server types — web, workers — each with its own config.

Roles are used to configure different types of servers in the deployment. The most common use for this is to run web servers and job servers.

Kamal expects there to be a web role, unless you set a different primary_role in the root configuration.

Role configuration#

Roles are specified under the servers key:

servers:

Simple role configuration#

This can be a list of hosts if you don't need custom configuration for the role.

You can set tags on the hosts for custom env variables (see dash docs env):

web:
  - 172.1.0.1
  - 172.1.0.2: experiment1
  - 172.1.0.2: [ experiment1, experiment2 ]

Custom role configuration#

When there are other options to set, the list of hosts goes under the hosts key.

By default, only the primary role uses a proxy.

For other roles, you can set it to proxy: true to enable it and inherit the root proxy configuration or provide a map of options to override the root configuration.

For the primary role, you can set proxy: false to disable the proxy.

You can also set a custom cmd to run in the container and overwrite other settings from the root configuration.

workers:
  hosts:
    - 172.1.0.3
    - 172.1.0.4: experiment1
  cmd: "bin/jobs"
  stop_timeout: 30

How long this role's container must keep running before the deploy accepts it, when there is no healthcheck to wait on. Overrides the root readiness_delay for this role only; roles with a healthcheck never wait on it.

readiness_delay: 4

Rolling boot#

The root boot key paces the deploy across the whole cross-role host list, so it cannot serialize one role's hosts while another role keeps booting in parallel. Set boot on the role instead and its hosts are paced on their own — a second host in a worker role finally buys the redundancy it looks like it buys.

limit is a count, or a percentage of the hosts this run is booting for the role (so --roles / --hosts narrow the denominator too); limit: 1 boots them one at a time. wait is the pause between hosts or groups, and defaults to none. It needs limit to do anything — without one the role's hosts boot in a single group, leaving no gap to pause in, and Kamal warns. Nothing waits after the final group.

A role using this key needs the role-first iteration of boot/parallel_roles. Kamal turns it on for you when you have not set it; an explicit parallel_roles: false is a conflict and raises instead.

boot:
  limit: 25%
  wait: 10

Replicas#

How many containers of this role run on EACH of its hosts. A process that cannot use more than one core by itself — open-source Sidekiq is one Ruby process — gets the rest of a bigger host this way, without declaring the same worker twice.

replicas: 2 is shorthand for { min: 2, max: 2 }; the default is one, which is the behaviour without the key. A deploy boots as many replicas as are running now, kept within min and max, so a count changed at runtime with dash scale set <role> <count> survives the next deploy. With nothing running it boots min. max is the ceiling for dash scale set.

Replicas of a proxied role are all targets of the role's one dash-proxy service, which balances across them. Replicas of any other role are independent containers. Replica 1 keeps the container name the role always had; replica 2 and up put the slot into the role segment (app-workers.2-<version>), and every replica of a scalable role gets the replica label and the DASH_REPLICA env var.

Every replica opens its own database pool, so pool × replicas × hosts has to fit the database's (or the pooler's) connection limit.

More than one replica cannot set the publish, p, name or hostname docker options, which every replica on a host would claim, and cannot yet be combined with proxy/sleep. Host volumes are shared by every replica on a host, which is fine for read-only config or a shared cache and wrong for a per-process store, so they warn.

replicas:
  min: 1
  max: 4

Drain#

How a replica of a role WITHOUT the proxy leaves when dash scale set removes it: signal is sent first (e.g. TSTP, so Sidekiq stops taking new jobs), then dash waits wait seconds before docker stop. A role with a sidekiq scale signal stops waiting as soon as Sidekiq reports the leaving containers' processes quiet with nothing busy (it reports both every few seconds), so wait is then the most it waits. Keep wait inside the stop budget described on the worker roles page. A role behind dash-proxy has no drain: the proxy drains it, so setting one there is an error.

drain:
  signal: TSTP
  wait: 20

Scale#

Extra hosts a role can run on beyond the ones listed under hosts, which stay the baseline: always on, deployed as before, never stopped by dash. The extra hosts are pool members that live in the cloud provider named under the root autoscale: key (see dash docs autoscale), not in this file. dash finds them by their labels — dash.service=<service>, dash.destination=<destination, or - without one> and dash.role=<role> — and every member that is started is a host of the role for every command; stopped members are never touched. A provider that cannot be reached fails the command. --hosts then names the member hosts to act on, with a warning — for one scaled role at a time (pick it with --roles when there are more).

min and max count HOSTS, the baseline included, so min is at least the number of hosts; replicas counts containers per host. dash scale set <role> <count> counts containers across all of them.

A scaled role behind dash-proxy needs the load balancer, which turns on by itself for it even with one baseline host; proxy/loadbalancer: false is an error for it.

schedule, signal, warmup, cooldown and step drive the autoscaling controller (dash autoscale run), which then owns the role's count: a manual dash scale set lasts until its next tick unless the role is paused (dash autoscale pause ROLE). A scaled role with neither a schedule nor a signal stays manual.

scale:
  min: 2
  max: 4

How extra hosts come to exist. power (the default) powers stopped members on and off again; they are created beforehand, with Terraform for example, carrying the three labels. create creates a member from template when one is needed and destroys it when it leaves. On UpCloud a stopped server's compute is free only on Cloud Native plans; any other plan bills a powered-off member as if it ran.

members: power

What a create member is built from (UpCloud): the template storage to clone, the plan and zone, the user dash connects as with its SSH keys, the private network (SDN) to attach — required when address is private — and cloud-init user data, for a Tailscale join for example. Only create uses it, and create requires it.

template:
  storage: 01234567-89ab-cdef-0123-456789abcdef
  plan: CLOUDNATIVE-8xCPU-16GB
  zone: de-fra1
  login_user: deploy
  ssh_keys:
    - "ssh-ed25519 AAAA... deploy"
  network: 03abcdef-0123-4567-89ab-cdef01234567
  user_data: |

!/bin/sh

tailscale up --authkey ...

Which of a member's addresses dash connects to: private (the default), public or utility.

address: private

Seconds from powering a member on (or creating it) until it answers SSH, default 300. The controller also replaces a started member that has not answered SSH for this long: out of the load balancer, powered off (deleted for create), and the next tick restores the count with a healthy one.

boot_timeout: 300

Windows of guaranteed capacity, in containers (the unit of dash scale set). From every minute cron matches, for for (seconds, or a number with s, m, h or d, at most 7d), the controller keeps at least min containers running; overlapping windows take the largest min. Outside every window it returns to scale min × replicas min. The target never goes above scale max × replicas max.

cron has five fields - minute, hour, day-of-month, month, day-of-week - each *, a number, a range a-b, a list a,b or a step */n or a-b/n; day-of-week 0 and 7 are Sunday. When both day fields are set, a day matches if either does. There are no names, L, W or #. It is evaluated in autoscale/timezone.

"The evening before the 1st and the 15th" has no exact cron: this example starts on the 14th and on each of the 28th to 31st (so on several evenings at a month end). When a few hours of lead are not needed, start on the day itself: 0 0 1,15 * *.

schedule:
  - cron: "0 22 14,28-31 * *"
    for: 30h
    min: 10

Seconds a member that just joined counts as warming up: the controller never scales in while one is, nor replaces it for not answering SSH. Default: boot_timeout.

warmup: 300

Seconds between the controller's actions. A scale-in step waits down (default 600) after the last scale-out or scale-in. A signal-driven scale-out waits up (default 60) after the last one. A schedule floor scales out at once, whatever the cooldown.

cooldown:
  up: 60
  down: 600

Containers added or removed per signal-driven step, and removed per scale-in step back to a floor; default replicas/max (one host's worth). A step lands on a count the hosts can split. Scale-out to a schedule floor goes straight to it.

step: 3

The reactive rules: the controller reads signal every tick and holds it inside a band. Above up/above for up/for it scales out by step, at most once per cooldown/up, up to scale max × replicas max. Below down/below for down/for it scales in by step, at most once per cooldown/down, never below the floor (scale min × replicas min, raised by schedule windows) and never while a member warms up. Inside the band it holds. A sample it cannot read holds the role (missing_data), and starts both windows over; a floor still applies.

source is one of:

  • sidekiq: the age in seconds of the oldest job across queues, read from Redis (autoscale/redis). Sidekiq 7's float seconds and Sidekiq 8's integer milliseconds are both read. Draining a Sidekiq container on scale-in ends as soon as Sidekiq reports it quiet with nothing busy, instead of always waiting drain/wait.
  • pgbus: the age in seconds of the oldest claimable message across queues, read from Postgres (autoscale/postgres): the pgmq table pgmq.q_<prefix><queue>, prefix defaulting to pgbus_. Scheduled messages do not count. pgbus has no quiet mode, so leave drain/signal unset and give the role a stop timeout of at least pgbus's drain_timeout.
  • prometheus: the value of one PromQL query (autoscale/prometheus), the largest when it returns several series. An empty result is a missing sample.

A role with a schedule and no signal keeps returning to its floor a step at a time.

Tuning: record a busy day with dash autoscale run --record FILE, then try a band, a step or a cooldown with dash autoscale simulate --samples FILE before deploying it. Judoscale's worker defaults make a sound start: a queue-latency band of 1-5 seconds, up after one breach, down after 10 minutes. In an app whose roles share a database, give every signalled role a hold_when guard on it. dash autoscale signal ROLE reads the signal and guards live, as the controller does. Simulation replays what the queue did with the containers that really ran, not the simulated ones; it starts its cooldowns at the tick that acted, where live they start once the scale finishes, and its breach windows empty - so it is a guide, not a forecast.

signal:
  source: sidekiq
  queues:
    - default
    - billing

Scale out above this, after this long above it (seconds, or a number with s, m, h or d, at most 1d). for defaults to 0: the first sample above.

up:
  above: 10
  for: 30s

Scale in below this, after this long below it (default 10m). up/above must be greater than down/below.

down:
  below: 2
  for: 10m

Saturation guards: while any query reads above its above - or cannot be read - a signal-driven scale-out holds (held_by_guard), since more containers would only queue on what is already full. source is prometheus (a PromQL query) or postgres (SQL, run read-only with a 5 second timeout; the first column of the first row). Guards never hold a schedule floor: a window is capacity asked for.

hold_when:
  - source: prometheus
    query: max(pgbouncer_pools_client_waiting_connections)
    above: 0
  - source: postgres
    query: SELECT count(*) FROM pg_stat_activity
    above: 180

Option values are shell-escaped before reaching docker run, but ${...} is deliberately left for the deploy host's shell to expand. Role env is never defined in that shell, so ${MY_VAR} resolves to empty. Use the bare $MY_VAR form, which is escaped and expands inside the container. Kamal rejects ${...} in health-* options, where the empty value would only surface as a deploy timeout.

options:
  memory: 2g
  cpus: 4
logging:
  ...
proxy:
  ...
labels:
  my-label: workers
env:
  ...
asset_path: /public

Healthcheck#

A role that does not run the proxy has no readiness gate of its own: the deploy only checks that the container is still running after readiness_delay seconds before stopping the old one. Declare a healthcheck and Kamal renders it into docker's own HEALTHCHECK flags, so the deploy waits for the container to report healthy instead.

port is required unless you set cmd. The default HTTP check is curl -f http://localhost:<port><path> || exit 1, so the image needs curl.

cmd runs inside the container via /bin/sh and can be anything that exits non-zero when unhealthy — no HTTP server and no published port needed. It may not contain ${...}: that would expand on the deploy host, not in the container.

Durations are seconds when given as a plain number, or any docker duration string ("90s", "1m30s"). interval defaults to 1 second so a deploy is not left waiting on docker's own 30 second default.

A healthcheck cannot be combined with health-* keys under options.

exec is the escape hatch for an image whose HEALTHCHECK you cannot change, or for an emergency override without a rebuild. Dash docker execs it on the deploy host once a second and gates the deploy on the exit code — no HTTP server and no published port needed, and unlike cmd it may use ${...}, which is quoted through to the container. It is strictly worse than cmd in the general case, so reach for it only when cmd is not available:

  • deploy-time only. Docker never runs it, so docker ps never shows (healthy) and docker inspect keeps no probe history.
  • each attempt costs a process spawn on the host (the whole wait is one SSH round trip, so the cost does not grow with how long the boot takes).
  • nothing outside a deploy ever runs it.

exec replaces docker's healthcheck rather than configuring it, so it cannot be combined with cmd, port, path, or any of the duration keys. The wait gives up at deploy_timeout; a probe that never exits zero fails the boot and leaves the old container running.

A non-proxied role with neither a healthcheck nor a health-cmd option warns on every deploy, because the readiness delay is the only thing standing between a container that starts and a container that serves. Write healthcheck: false to accept that gap explicitly and silence the warning.

healthcheck:
  port: 7434
  path: /readyz
  cmd: "pgrep -f bin/jobs"
  exec: "bin/ready-check"
  interval: 5
  timeout: 3
  retries: 3
  start_period: 60
  start_interval: 1
Generated from the gem's lib/dash/configuration/docs/role.yml — the same reference dash docs role prints in your terminal, so this page always matches your installed version.