Proxy management
Kamal manages a kamal-proxy service that accepts public HTTP and HTTPS traffic and sends it to deployed application roles or accessories. Proxy management covers the proxy container lifecycle and keeps each reachable service registered with the proxy as containers change during deployment.
Proxy responsibility
The proxy is the shared traffic entry point for roles and accessories that opt into proxying. It runs on the union of hosts used by proxied roles and proxied accessories. See command execution for the command layer that invokes these operations and service configuration for the wider configuration model.
Proxy host scope
Kamal derives the proxy host set from all roles and accessories with proxying enabled. The primary role uses the proxy by default. Other roles need an explicit proxy setting, while an accessory uses the proxy when its configuration includes a proxy section.
The configuration must give one host a single proxy run definition. This keeps the container image and listener behavior consistent when several services share that host. A host can still have different application routing rules because those rules belong to each service.
References: lib/…/configuration.rb• L164-189 lib/…/role.rb• L167-184 lib/…/accessory.rb• L117-136
Traffic entry point
The proxy normally exposes HTTP on port 80 and HTTPS on port 443. A service can narrow routing by host name or path prefix. It can also select an application port, health check behavior, request buffering, timeouts, forwarded headers, and TLS behavior.
Automatic TLS needs a host name and one deployment host. Custom certificates support cases where the service uses more than one host. These settings affect how a service is registered with the running proxy rather than how the proxy container itself is started.
References: lib/…/proxy.yml• L3-11 lib/…/proxy.yml• L15-48 lib/…/proxy.yml• L66-120 lib/…/proxy.rb• L20-99
Proxy boot and runtime
Proxy boot prepares the shared network and proxy state on the selected hosts. It then starts the existing proxy container when possible or creates a new one from the configured run definition. The container uses persistent proxy configuration and a host-backed directory for per-service routing data.
The proxy/run settings describe container-level behavior. They select the image and version, listener ports, published interfaces, metrics exposure, logging limits, debug mode, and extra container options. These settings are separate from the per-service proxy settings that describe routing.
Boot operation
kamal proxy boot makes the proxy ready without replacing a healthy existing container. It creates the shared Docker network for all Kamal hosts, checks that an existing proxy is not below the minimum supported version, prepares the service configuration directory, and starts or runs the proxy on each proxy host.
This operation is safe to repeat. A stopped container can be started again, and a missing container can be created from the current run configuration.
References: lib/…/proxy.rb• L1-23 lib/…/proxy.rb• L10-37 lib/…/proxy.rb• L136-145
Run configuration
The proxy run definition controls the shared runtime contract. Kamal defaults to ports 80 and 443 and to the supported kamal-proxy image. It can publish those ports, bind them to selected IP addresses, expose a metrics port, set log size, and pass extra container options.
The run definition also mounts the shared service configuration directory. This lets application and accessory routing records remain available when the proxy container is replaced.
References: lib/…/run.rb• L1-14 lib/…/run.rb• L16-102 lib/…/run.rb• L104-123 lib/…/proxy.rb• L24-35
Application routing
Application routing connects a running role container to the proxy. During an application boot or deployment, Kamal first obtains the new container endpoint. It then registers that endpoint with the proxy together with the role's host, TLS, health, path, and request handling rules.
This is the handoff that makes a new application version reachable. The proxy can move traffic to the new endpoint before the old container is stopped, which supports gapless deployment behavior. See application deployment for the wider application lifecycle.
This diagram shows how a deployed service becomes reachable through the shared proxy.
flowchart LR
D[Service deployment] --> E[Running container endpoint]
E --> R[Proxy route]
T[Public request] --> R
R --> E
Deployment registration
The application command registers a role with the proxy by service name and target endpoint. The target is the running container selected for that role and version. A role without proxying follows the normal container health path instead of creating a proxy route.
The proxy configuration is application-specific. Host names, path prefixes, TLS, health checks, and timeouts therefore apply to one role registration and do not become shared defaults for other applications on the host.
References: lib/…/boot.rb• L46-60 lib/…/proxy.rb• L1-30 lib/…/proxy.rb• L66-99
Service state transitions
Kamal removes a role's proxy registration before it stops the running container. It restores the registration when kamal app start starts that container again. The live and maintenance commands change the proxy's serving state without changing the application container.
Maintenance can allow in-flight requests to drain and can provide a message for new clients. This keeps traffic control in the proxy while the application process remains available for operational work.
References: lib/…/app.rb• L43-79 lib/…/app.rb• L255-275 lib/…/proxy.rb• L8-18 lib/…/role.rb• L82-86
Accessory routing
An accessory is an auxiliary service such as a database or queue worker. When an accessory has proxy settings, Kamal treats it as another proxy target and registers its service name and running container endpoint with the same proxy used by applications.
Accessory routing follows the accessory container lifecycle. Boot and start add the route after the container is running. Stop removes the route before the container stops. Reboot repeats this process after the new container is ready. See accessory operations for the full accessory lifecycle.
Accessory registration
The accessory proxy record supplies the target port and the same family of traffic rules used for an application. The accessory command sends this record to kamal-proxy after it finds the live accessory container.
This model lets one proxy host route both application traffic and selected accessory traffic while keeping each service's route separate.
References: lib/…/accessory.rb• L117-136 lib/…/accessory.rb• L5-41 lib/…/accessory.rb• L94-124 lib/…/proxy.rb• L1-16
Proxy reboot and operations
Proxy reboot replaces the proxy container with a new container built from the current run configuration. It is the recovery path for an old proxy version and the normal way to apply changes that affect the proxy container itself. Reboot causes a brief outage on each host.
Reboot sequence
The reboot flow follows a fixed order:
- Confirm the outage unless the command is explicitly confirmed.
- Run the pre-reboot hook for the current host group.
- Stop and remove the old proxy container.
- Prepare the shared service configuration directory.
- Run the configured proxy image.
- Run the post-reboot hook after the host group completes.
By default, hosts reboot in parallel. The rolling option processes one host group at a time so other proxy hosts can continue to serve traffic while each host is replaced.
References: lib/…/proxy.rb• L106-132 lib/…/proxy.rb• L10-24 test/…/proxy_test.rb• L8-24
Runtime inspection
Proxy operations include start, stop, restart, details, logs, and remove. Start and restart act on the existing container. Details and logs help inspect the serving layer. Remove also clears the proxy image and host state, so Kamal blocks it when applications remain unless the operator forces the action.
The older boot_config command can manage host-side boot files, but the supported source for new proxy runtime settings is proxy/run in the deploy configuration.
References: lib/…/proxy.rb• L25-104 lib/…/proxy.rb• L175-247 lib/…/proxy.rb• L249-296
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the host selection rules aligned with proxy boot, application routing, and accessory routing. A service that adds proxying must also place its host in the proxy host set.
- Keep the proxy run contract aligned with the container image, published ports, mounted service configuration, and minimum supported proxy version.
- Keep application and accessory route removal paired with container stop operations. A stale route can send traffic to a container that no longer serves.
- Keep TLS validation aligned with host count and certificate source. Automatic certificates and custom certificates have different host requirements.
- Keep reboot hooks and rolling behavior aligned with the expected outage window for all proxy hosts.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Different proxy run settings apply to one host | Kamal cannot select one shared proxy runtime | Configuration validation rejects conflicting run definitions |
| A proxy version is below the supported minimum | Boot stops instead of starting an incompatible proxy | Boot checks the installed version; reboot replaces the container |
| Automatic TLS is used without a host or across several hosts | Certificate setup cannot meet the proxy's requirements | Validation requires a host and limits multi-host automatic TLS |
| A running application or accessory is stopped without route removal | The proxy can retain a target that no longer serves | Lifecycle commands remove routes before stopping containers |
| Proxy removal is requested while applications remain | Removing the shared entry point can break deployed services | Removal checks installed application directories unless forced |
| Ports or bind IPs are set while publishing is disabled | The requested listener settings cannot take effect | Configuration validation rejects that combination |
Key files
| File | Why to read it |
|---|---|
| lib/…/proxy.rb | Defines proxy boot, reboot, runtime inspection, and removal operations. |
| lib/…/proxy.rb | Shows the shared proxy container actions used by the CLI. |
| lib/…/proxy.rb | Defines per-service routing behavior such as hosts, TLS, health checks, and target options. |
| lib/…/run.rb | Defines the shared proxy container runtime contract. |
| lib/…/proxy.rb | Shows how application targets are registered and removed. |
| lib/…/proxy.rb | Shows how accessory targets use the same proxy service. |
| lib/…/boot.rb | Shows where application boot hands a new container endpoint to the proxy. |
| lib/…/accessory.rb | Shows where accessory boot, start, stop, and reboot update proxy routes. |
| lib/…/proxy.yml | Describes the user-facing proxy and proxy run settings. |