Skip to content

Serve a Run service through a load balancer

Send a load balancer's HTTP and HTTPS traffic to a Run service, and optionally turn off the service's run URL.

Updated View as Markdown

A load balancer can forward requests to a Run service, so the service answers on your domain and certificate, behind your path rules and WAF. Both internet and internal load balancers work. You can then switch off the service’s run URL so the load balancer is the only way in.

Create a Run target group

A Run target group is an http target group that names a service instead of holding targets. Create it in the service’s project, in the VPC of the load balancer that will use it.

In the load balancer’s project, open Load balancers, then Target groups, and create one. Enter a Name, pick the VPC, set Type to Run service, and pick the service in the Run service select (Type offers Targets and Run service).

ezgh lb target-groups create web --vpc vpc_5p7r9s3t1vxz --run-service rsv_7hq2m0x9ka3c

Call CreateTargetGroup with protocol http and runService:

{ "name": "web", "vpc": "vpc_5p7r9s3t1vxz", "protocol": "http", "runService": "rsv_7hq2m0x9ka3c" }

runService can’t change after create. A Run group has no targets of its own: you register none, and Run decides which instances take each request, starting one when none is running.

Use the group in a listener

Use the group in an http or https listener’s default action or in a rule, as any http group (Route HTTP traffic):

ezgh lb listeners create lbr_4k2m9x0a7qpe --protocol https --port 443 \
  --certificate crt_8s4f2k9d1mzq --forward tgp_7t3n1v8c2wzd

It can sit beside other groups in one action, with weights:

rules.jsonjson
[
  {
    "name": "api",
    "match": { "paths": [{ "type": "prefix", "value": "/api" }] },
    "action": {
      "type": "forward",
      "forward": {
        "targetGroups": [
          { "targetGroup": "tgp_7t3n1v8c2wzd", "weight": 90 },
          { "targetGroup": "tgp_3a5s7d9f1ghj", "weight": 10 }
        ]
      }
    }
  }
]

A tcp or tls listener can’t use a Run group.

Turn off the run URL

A service’s ingress is all (the default), which answers on its run URL and through load balancers, or loadBalancers. While set to load balancers only, the service has no URL, and only load balancers with a Run group for the service reach it. The API value is loadBalancers; the CLI value is load-balancers.

Open the service’s Settings, then Ingress, choose “Load balancers only” (the other choice is “Run URL and load balancers”), and Save. The bound target groups are listed there, and the service’s URL shows as –.

ezgh run update api --ingress load-balancers

Send PATCH to the service with { "ingress": "loadBalancers" }. The service’s url is then null.

Set it back to all the same way: the service gets the same URL again. Changing it takes effect at once and makes no revision. The service’s access applies to requests from load balancers too.

What your app receives

Header Value
Host The client’s, unchanged: your domain.
X-Forwarded-For The client’s address, appended to any the client sent. Trust only the last entry.
X-Forwarded-Proto http or https, the listener’s protocol.

Permissions

  • To pick a service and bind it: run.services.list and run.services.invoke on it, and lb.targetGroups.create. RunInvokeAccess includes run.services.invoke but not run.services.list; RunFullAccess includes both.
  • To change a service’s ingress: run.services.update.
  • Changing a listener that uses the group needs only the load balancer permissions.

Limits

  • The service, the target group and the load balancer are in the same project.
  • WebSockets, HTTP/2 to the container and gRPC aren’t supported, as on the run URL.
  • A service with a Run group can’t be deleted until the group is deleted: 409 service_in_use.
Navigation

Type to search…

↑↓ navigate↵ selectEsc close