Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal-proxy

Lightweight proxy server for Kamal

View on GitHub

15 documents · Updated Nov 18, 2026

docs / service-deployment

Service deployment workflow

The service deployment workflow turns a service name, target hosts, and routing settings into a live proxy route. It prepares and checks new targets before it changes traffic, then drains the previous targets so deployments can avoid downtime.

Deployment model

The deploy <service> command is the normal path for creating a service or replacing its active targets. The command sends the deployment request to the running proxy, which owns service registration, target health, traffic routing, and connection draining. See the operator CLI, service operations, and service and target lifecycle pages for the wider command and state model.

Service registration

The proxy treats a service as the routing unit that joins a name with host and path rules, service behavior, and target settings. A first deployment creates that unit. A later deployment updates its settings and replaces its active target group.

Registration is atomic from the routing point of view. The proxy checks that the new host and path rules do not conflict with another service before it installs the new group. A failed deployment therefore does not replace the current service route.

References: internal/…/router.go• L151-177 internal/…/router.go• L382-405 internal/…/service.go• L216-229

Target setup

The deployment command accepts write targets through --target and read-only targets through --read-target. The proxy builds one target group from both sets. Write targets can serve all request types. Read-only targets serve eligible read traffic when they are healthy.

Service settings define where the group receives traffic. Hosts select the request host and path prefixes select the request path. TLS settings apply the required host and certificate rules. Target settings define the health endpoint and the request behavior that the proxy uses after activation.

References: internal/…/deploy.go• L29-42 internal/…/commands.go• L19-26 internal/…/load_balancer.go• L24-45 internal/…/service.go• L101-169

Active deployment

An active deployment follows a prepare, verify, install, and drain sequence. This order keeps the old group available while the new group is being checked.

The workflow moves through these stages:

  1. Validate and normalize service settings.
  2. Create the new target group and start health checks.
  3. Wait for every target to become healthy, unless --force skips this wait.
  4. Register or update the service and install the group as its active group.
  5. Dispose of the replaced group and drain its in-flight connections for the configured drain period.
  6. Save the service state for later restoration.

The default deployment timeout and drain timeout are both 30 seconds. Operators can change them with --deploy-timeout and --drain-timeout. A health failure or a host conflict stops the workflow before the active route changes.

This diagram shows how a new target group becomes active while existing requests leave the old group.

flowchart LR
    A[deploy service] --> B[Validate service settings]
    B --> C[Build target group]
    C --> D{Targets healthy?}
    D -- No --> E[Keep current route]
    D -- Yes --> F[Install active group]
    F --> G[Drain old group]
    G --> H[Persist service state]
    C -. --force .-> F

References: internal/…/deploy.go• L44-50 internal/…/router.go• L151-177 internal/…/router.go• L363-379 internal/…/load_balancer.go• L136-172

Rollout deployment

The rollout deploy <service> command prepares a second target group for an existing service. It keeps the current active group in place and installs the new group in the rollout slot. It reuses the service's current routing and target settings, so this command changes the candidate targets rather than the service boundary.

Rollout deployment uses the same health and drain controls as active deployment. It requires --target and can also receive read-only targets. The service must already exist. After the rollout group is ready, traffic still follows the active group until an operator changes the rollout state.

References: internal/…/rollout.go• L9-20 internal/…/rollout_deploy.go• L15-41 internal/…/router.go• L180-207

Rollout control

Rollout control moves traffic between the active and rollout groups without rebuilding the service. Operators can set a percentage or an allowlist, enable or disable the split, and remove the rollout group after the change is complete.

The rollout split applies to requests that carry the rollout identity cookie. An enabled split sends matching identities to the rollout group according to the configured percentage or allowlist. Disabling the split leaves the rollout group available but sends traffic back to the active group. Removing the rollout group clears the candidate and drains its connections.

Use traffic controls for request selection rules and service operations for pause, stop, resume, and remove actions.

References: internal/…/rollout_set.go• L15-39 internal/…/rollout_enable.go• L15-34 internal/…/rollout_disable.go• L15-34 internal/…/rollout_remove.go• L15-36 internal/…/router.go• L209-258 internal/…/rollout_controller.go• L40-55

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the CLI deployment arguments aligned with the RPC argument groups. The active command carries service and target settings. Rollout deployment carries only target and deployment settings.
  • Preserve the prepare-before-install order. Moving installation before health or conflict checks can expose an unusable target or replace a valid route.
  • Keep active and rollout target slots distinct. Rollout controls assume that an existing service has a separate candidate group.
  • Keep drain behavior paired with replacement and removal. A group must stop accepting new work before old connections are released.
  • Keep service state persistence aligned with target replacement and rollout state changes. A restart must not restore a state that differs from the live routing state.

Important failure modes

TriggerConsequenceGuard
A target does not pass its health check before the deployment timeoutThe new group is rejected and the current active route stays in placeUse the health path and timeout that match the service. Use --force only when health checks are not suitable
New host or path rules conflict with another serviceThe deployment fails before the new group is installedGive each service a non-overlapping host and path scope
TLS is enabled without a valid host ruleService validation fails and no TLS route is createdSet a host for certificate use. Use the on-demand TLS mode only with its allowed option set
Rollout deployment targets a service that does not existThe rollout group cannot be createdRun an active deployment before rollout deploy
Rollout control runs without a rollout groupThe split or enable operation returns a missing-rollout errorDeploy rollout targets before setting or enabling the split

Key files

FileWhy to read it
internal/…/deploy.goDefines the active deployment command and its operator-facing settings
internal/…/rollout_deploy.goDefines the command that stages rollout targets
internal/…/rollout_set.goShows how operators choose percentage or allowlist traffic
internal/…/commands.goConnects CLI requests to deployment and rollout actions
internal/…/router.goCoordinates validation, target preparation, service registration, replacement, and draining
internal/…/service.goDefines service settings and the active and rollout target slots
internal/…/load_balancer.goDescribes target health readiness and connection draining at deployment time