Skip to content

[Feature]: Support in-place gateway recreation to preserve ALB/IP and avoid DNS changes #3924

Description

@Outvoker

Problem

Summary

When a dstack gateway needs to be recreated (e.g., to refresh the underlying EC2 instance), the current behavior forces downstream DNS or CNAME changes because the AWS Load Balancer and/or EC2 public IP change.
We'd like to request support for in-place gateway recreation that preserves the externally-visible endpoint.

Current Behavior

Gateway with cert (HTTPS)

  • Creating a gateway on AWS provisions an Application Load Balancer (ALB) and a target group pointing to a backing EC2 instance.
  • Recreating the gateway provisions a new ALB and a new EC2 instance.
  • The previous ALB does not appear to be cleaned up automatically.
  • Because the ALB DNS name changes, any CNAME pointing to the gateway must be updated.

Gateway without cert

  • Recreating the gateway provisions a new EC2 instance with a different public IP.
  • For wildcard-domain setups, this requires a fresh DNS change request and incurs downtime during propagation.

Solution

Requested Behavior

Gateway with cert

Support in-place recreation that:

  • Keeps the existing ALB.
  • Replaces only the EC2 instance behind it (update the target group to point to the new instance).
  • Cleans up the old EC2 instance after the new one is healthy.

Result: no CNAME change required, minimal/zero downtime.

Gateway without cert

Support in-place restart/recreation that:

  • Preserves the existing public IP (e.g., via Elastic IP reassociation, or by reusing the instance and replacing only the OS/kernel).

Result: no DNS change required.

Motivation / Background

We have several dstack gateways that were created some time ago and are now running Linux kernel versions that no longer meet our internal security compliance policy. The policy requires that the kernel release
date be within the last 180 days, with a 60-day remediation window once an asset is flagged.

To remediate, we need to refresh these gateways onto a current AMI/kernel. Today, doing so forces:

  1. A new ALB DNS name (with-cert case) — every consumer's CNAME must be updated.
  2. A new public IP (without-cert case) — every wildcard-domain DNS record must be updated, with downtime during propagation.

Because gateway recreation will be a recurring operational task (driven by quarterly patching cycles, not just one-time kernel upgrades), the DNS-change toil compounds significantly. In-place recreation would let
us meet our patching SLA without coordinating downstream DNS changes each cycle.

Workaround

No response

Would you like to help us implement this feature by sending a PR?

No

Activity

  1. self-assigned this
    on Jun 2, 2026
  2. jvstme commented on Jun 15, 2026

    @jvstme
    Collaborator

    Most items from #3959 are going to be a prerequisite. Working on them now

  3. github-actions commented on Jul 16, 2026

    @github-actions

    This issue is stale because it has been open for 30 days with no activity.

  4. jvstme commented on Aug 14, 2026

    @jvstme
    Collaborator

    dstack 0.21.1 allows you to migrate the gateway to a new instance through a sequence of scaling out and scaling in.

    • For gateways with ACM certificates, this can be done without downtime and without DNS changes. The same ALB is preserved.
    • For gateways without a certificate, DNS changes are still required. Supporting redeployment without DNS changes for such gateways is a work in progress.

    Instructions for updating a single-replica gateway with an ACM certificate

    1. Update the server and the CLI to 0.21.1 or newer.

    2. Locate the YAML configuration that was used to create the gateway, or restore it from dstack gateway get --json <gateway name>.

    3. Set replicas: 2 in the configuration.

    4. Apply the configuration.

      $ dstack apply -f my-gateway.dstack.yml
      Project        main                    
      User           admin                   
      Configuration  my-gateway.dstack.yml 
      Type           gateway                 
      Backend        aws                     
      Region         eu-west-1               
      Domain         example.com      
      Replicas       2                       
      
      Found gateway my-gateway. Detected changes that can be updated in-place:
      - replicas
      
      Update the gateway? [y/n]: y
      NAME        BACKEND          HOSTNAME                                                   DOMAIN       DEFAULT  STATUS  
      my-gateway  aws (eu-west-1)  dstack-xaoxm1dz-lb-1834091824.eu-west-1.elb.amazonaws.com  example.com  ✓        running

      NOTE: Make sure dstack apply says the gateway can be updated. If it says the gateway cannot be updated, do not confirm, as that would result in gateway termination.

    5. Wait until the second replica is running. This may take about two minutes.

      $ dstack gateway -w
      NAME          BACKEND           HOSTNAME                                                   DOMAIN       DEFAULT  STATUS  
      my-gateway                      dstack-xaoxm1dz-lb-1834091824.eu-west-1.elb.amazonaws.com  example.com  ✓        running 
          replica=0  aws (eu-west-1)  52.48.189.229                                                                    running 
          replica=1  aws (eu-west-1)  3.248.191.93                                                                     running
    6. Verify that existing services have been registered on the second replica. This may take a few seconds.

      $ # UPD: on 0.20.3+, use --within-gateway instead of --target-gateway
      $ dstack event --target-gateway my-gateway
      [2026-08-14 19:57:06] [👤admin] [gateway my-gateway] Gateway updated. Changed fields: replicas
      [2026-08-14 19:59:08] [run first-service, gateway my-gateway] Service registered on gateway replica 1
      [2026-08-14 19:59:08] [run second-service, gateway my-gateway] Service registered on gateway replica 1
      [2026-08-14 19:59:08] [job second-service-0-0, gateway my-gateway] Service replica registered on gateway replica 1
      [2026-08-14 19:59:08] [job first-service-0-0, gateway my-gateway] Service replica registered on gateway replica 1
    7. Verify that the services are responding as expected.

    8. Set replicas: 1 in the configuration.

    9. Apply the configuration.

    10. Wait until the first replica is terminated.

      $ dstack gateway -w
      NAME          BACKEND           HOSTNAME                                                   DOMAIN       DEFAULT  STATUS     
      my-gateway                      dstack-xaoxm1dz-lb-1834091824.eu-west-1.elb.amazonaws.com  example.com  ✓        running    
          replica=0  aws (eu-west-1)  52.48.189.229                                                                    terminated 
          replica=1  aws (eu-west-1)  3.248.191.93                                                                     running
  5. jvstme commented on Aug 27, 2026

    @jvstme
    Collaborator

    Today's 0.21.3 release addresses the part about gateways without certificates — it is now possible to create gateways without a certificate while still using an ALB (#4219). Such gateways can then be redeployed without downtime using the sequence described in my comment above.

    Existing certificate: null gateways can be migrated to the new model using the following sequence:

    1. Create a new gateway with the same domain, but with load_balancer: { type: alb }.
    2. Move the services from the old gateway to the new one. This can be done without stopping the services (Support in-place update for service gateway #4221).
    3. Update the DNS records to point to the new gateway's ALB.
    4. Delete the old gateway.

    Service downtime is expected during steps 2–3 and while the DNS changes propagate. However, this is a one-time disruptive migration; future redeployments of the new gateway can be performed without downtime thanks to the ALB

  6. jvstme commented on Sep 1, 2026

    @jvstme
    Collaborator

    I believe the feature is ready, so I’ll close the ticket. If anything is missing, don’t hesitate to reopen it, open a new ticket, or contact us directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions