Application topology configuration
Application topology configuration defines the hosts that run an application and the rules used to reach and update them. It also controls rollout pacing, host storage, SSH access, command shortcuts, and the checks that stop an unsafe or incomplete deployment before it starts. It is one part of the broader deployment configuration system, alongside service configuration and environment and secrets.
Configuration scope
Kamal reads a base deployment file and can merge a destination-specific file when a destination is selected. The merged settings become one model of the application, its hosts, and its runtime access; commands then use that model for deployment and operations.
flowchart LR
Base[Base deployment settings] --> Merge[Configuration merge]
Destination[Destination settings] --> Merge
Merge --> Validate[Topology validation]
Validate --> Plan[Deployment and host operations]
The root settings establish the application identity and the shared host settings. Role settings can then specialize behavior for one group of hosts without changing the rest of the application.
Boot coordination
Boot settings control how quickly new application containers start across the topology. They let an operator trade rollout speed for lower load and smaller failure impact.
Host rollout pacing
Kamal can boot all hosts in parallel by default or process a fixed number or percentage at a time. A percentage is calculated from the total host count and always produces at least one host in a group. A wait value adds a pause between groups, while parallel_roles controls whether several roles on the same host start together or in sequence.
References: lib/…/boot.rb• L1-29 lib/…/boot.yml• L1-21
Application topology
The topology maps application roles to remote hosts. A simple deployment uses one host list and implies the web role; a larger deployment names roles such as web and workers so each group can have its own command, resources, labels, logging, proxy behavior, or environment.
Host placement
Each role contains hosts and may attach tags to them. Tags provide a way to apply host-specific environment settings without creating a separate role. A role can use a short host list when its behavior is shared, or a structured definition when it needs role-specific settings.
flowchart TD
Servers[servers setting] --> Layout{Host list or role map}
Layout --> Web[Implicit web role]
Layout --> Roles[Named roles]
Roles --> Hosts[Hosts with optional tags]
Web --> Hosts
Hosts --> Containers[Role containers on remote hosts]
The primary role identifies the main application group and defaults to web. Its first host is the primary host used by operations that need one representative application host. A deployment may select another primary role when no web role exists.
References: lib/…/servers.rb• L1-25 lib/…/role.rb• L30-40 lib/…/role.rb• L190-210 lib/…/servers.yml• L1-27 lib/…/role.yml• L1-54
Role specialization
The primary role runs the proxy by default. Other roles do not run it unless their role settings enable it. This lets web traffic and background work share a deployment while keeping their process and host behavior separate. Role settings can also change the container command, stop timeout, Docker options, labels, logging, environment, and asset path.
Roles that use automatic SSL need a single host unless they provide custom certificates. Different SSL roles cannot claim the same proxy host. These limits keep certificate ownership and request routing unambiguous; see service configuration for the proxy model.
References: lib/…/role.rb• L42-91 lib/…/role.rb• L160-187 lib/…/role.yml• L24-54 lib/…/configuration.rb• L144-177 lib/…/configuration.rb• L393-405
Command aliases
Aliases give a deployment a short name for a repeated Kamal command. They are operator-facing shortcuts, so they affect how people invoke an application but do not change its host topology.
Alias names
An alias name uses lowercase letters, numbers, hyphens, or underscores. It cannot replace a built-in Kamal command. Its command text may include a destination flag when the shortcut is intended for one deployment target.
References: lib/…/alias.rb• L1-15 lib/…/alias.rb• L1-15 lib/…/alias.yml• L1-29
Host storage
Volume settings define host-to-container mounts that the application needs at runtime. A mount can include an access mode, and a relative host path is resolved from the current working directory when Docker receives the mount.
Application volumes
Root-level volumes apply to the application containers. Asset bridging is a related role-level mount: when an asset path is configured for a proxied role, Kamal maps built asset files into the container so old and new asset names can work during a rollout. The asset path and ordinary volumes therefore affect different parts of runtime state and should not be treated as interchangeable.
References: lib/…/configuration.rb• L220-225 lib/…/volume.rb• L1-29 lib/…/role.rb• L133-158 lib/…/configuration.yml• L39-43
SSH access
SSH settings define how Kamal reaches the configured hosts before it can perform remote work. The defaults target root on port 22; deployments that use another account must prepare that account with the access and Docker rights needed by Kamal. Remote command behavior is covered in remote execution.
Connection access
SSH can use a jump host or a custom proxy command. It can load private key files or secret-backed key data, limit authentication to those keys, select OpenSSH configuration files, and control agent forwarding. SSH keepalive is enabled for the connection so long-running operations can detect a lost session.
References: lib/…/ssh.rb• L1-75 lib/…/ssh.yml• L1-81
Validation rules
Validation runs while Kamal builds the configuration model. It rejects unknown or wrongly typed settings and then checks relationships that simple type checks cannot catch. This makes a configuration failure occur before deployment work reaches a remote host.
Topology constraints
The main topology checks protect the minimum structure needed for a deployment:
serviceandregistryare required, and an image must be available. A local registry can use the service name as the image name.- The server list must be a host list, a role map, or absent only when accessories provide the deployment targets.
- The primary role must exist and must have a host. Every other role must also have a host unless
allow_empty_rolesis enabled. - A service name may contain only letters, numbers, hyphens, and underscores.
retain_containersmust be at least one, andminimum_versioncannot require a newer Kamal version than the running one.- When
require_destinationis enabled, a destination must be supplied.
References: lib/…/configuration.rb• L54-91 lib/…/configuration.rb• L323-375 lib/…/servers.rb• L1-7 lib/…/role.rb• L1-13
Configuration shape checks
The validator checks each section against its allowed shape and reports the path of the bad value. Root configuration permits x- extension keys for YAML reuse, while nested configuration rejects unknown keys. Host entries must be strings or single-entry host-to-tag maps, and role labels cannot overwrite the reserved service, role, or destination labels.
References: lib/…/validation.rb• L4-27 lib/…/validator.rb• L15-60 lib/…/validator.rb• L118-135 lib/…/validator.rb• L208-232
Cross-setting checks
Some rules compare settings across roles or across the local and remote parts of a deployment. Kamal rejects conflicting proxy run settings on one host and requires an SSH URL when a local registry is paired with a remote builder. It also validates hook output levels and blocks old Traefik reboot hook names so an outdated hook cannot silently run under a new proxy setup.
References: lib/…/configuration.rb• L383-429 lib/…/configuration.rb• L435-447
Change checklist
When these files or sections are changed, remember to consider these:
- Changing the
serversshape affects the impliedwebrole, primary-role selection, host counts, boot limits, and any tag-based environment settings. - Changing role proxy or SSL settings affects host uniqueness rules and the routing contract described in service configuration.
- Changing SSH key names or
key_datachanges the secret contract used by environment and secrets and the connection behavior in remote execution. - Changing volume or asset paths affects both Docker mount arguments and the location of files prepared for a rollout.
- Adding a configuration key requires its validation example and any dependent cross-setting checks to accept it.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The primary role is missing or has no host | Configuration stops before deployment | Require a defined primary role with at least one host |
| A non-primary role has no host | The role cannot run its intended workload | Keep allow_empty_roles false unless an empty role is deliberate |
| Two SSL roles use the same proxy host | Certificate and request routing can conflict | Reject duplicate SSL proxy hosts |
| A local registry uses a remote builder without an SSH URL | The builder cannot use the required remote path | Require an ssh:// remote builder URL |
| An alias matches a built-in command | The shortcut can shadow normal CLI behavior | Reject reserved alias names |
| A volume uses the wrong host or container path | Data is mounted in the wrong place or the container fails | Validate the mount contract before runtime |
Key files
| File | Why to read it |
|---|---|
| lib/…/configuration.rb | See how the complete configuration model is assembled and how global topology rules are enforced. |
| lib/…/servers.rb | See how a host list becomes the set of application roles. |
| lib/…/role.rb | See how one role maps hosts to role-specific runtime behavior. |
| lib/…/boot.rb | See how rollout pacing is derived from the host count. |
| lib/…/ssh.rb | See the connection options that make remote hosts reachable. |
| lib/…/volume.rb | See how a host-to-container mount becomes a Docker volume argument. |
| lib/…/validator.rb | See the shared rules for configuration shape, extensions, hosts, labels, and options. |
| lib/…/role.yml | See the supported role concepts and their intended deployment shape. |
| lib/…/ssh.yml | See the supported SSH access model and its defaults. |