---
title: "Serve a Run service through a load balancer"
description: "Send a load balancer's HTTP and HTTPS traffic to a Run service, and optionally turn off the service's run URL."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Serve a Run service through a load balancer

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](/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](/load-balancers/target-groups) 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.

### Console

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).
### CLI

```sh
ezgh lb target-groups create web --vpc vpc_5p7r9s3t1vxz --run-service rsv_7hq2m0x9ka3c
```
### API

Call [CreateTargetGroup](/lb-api/CreateTargetGroup/) with `protocol` `http` and `runService`:

```json
{ "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](/load-balancers/http)):

```sh
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:

```json title="rules.json"
[
  {
    "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`.

### Console

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 –.
### CLI

```sh
ezgh run update api --ingress load-balancers
```
### API

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](/run/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`.

Source: https://docs.ezghcloud.com/run/serve-through-a-load-balancer/index.mdx
