Clusters and endpoints
Define backends and pick the right cluster type.
Clusters: where the backends live
A cluster is a named group of backends Envoy can send traffic to. Every route ends in a cluster name. The cluster itself owns:
- The list of endpoints (IP:port instances).
- The load-balancing policy (round-robin, least-request, ring-hash, …).
- Health checks (active and passive).
- Circuit breakers (max connections, max requests, …).
- Upstream TLS config (Envoy → backend, distinct from downstream TLS).
When you point a route at cluster: payments_service, Envoy picks one
endpoint from that cluster's pool, opens (or reuses) a connection, and
forwards the request.
The four cluster types you'll meet
type | What endpoints look like | When to use |
|---|---|---|
STATIC | Literal IP:port pairs | Local testing, fixed infra |
STRICT_DNS | Hostname → all A records | Service discovery via DNS |
LOGICAL_DNS | Hostname → first valid record (lazy) | Long-lived upstreams (e.g. external APIs) |
EDS | Endpoints arrive via xDS | Dynamic / service mesh (Istio uses this) |
There's also ORIGINAL_DST for transparent proxies, which we'll skip.
STATIC accepts only literal addresses like 10.0.0.5
or 127.0.0.1. Pointing it at api.example.com won't
resolve — Envoy will accept the config and then fail to connect. Use
STRICT_DNS the moment you have hostnames.
A two-cluster config
Let's evolve the hello-world into something with two backends. We'll route based on path in the next lesson — for now, just see the cluster shape.
clusters:
- name: httpbin
type: LOGICAL_DNS
connect_timeout: 1s
load_assignment:
cluster_name: httpbin
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address: { address: httpbin.org, port_value: 80 }
- name: nginx_local
type: STATIC
connect_timeout: 1s
load_assignment:
cluster_name: nginx_local
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address: { address: 127.0.0.1, port_value: 8080 }
Two clusters, two completely different "types" of backend — one external by DNS, one local by IP — but the same cluster shape.
Endpoints come in groups
Notice the structure: endpoints[] → lb_endpoints[] → endpoint. The
outer list is locality groups (used for zone-aware routing); the inner
list is the actual endpoints inside a locality. For local dev you'll always
have one outer entry and a few inner ones.
load_assignment:
cluster_name: api
endpoints: # locality groups
- lb_endpoints: # endpoints within this locality
- endpoint: { address: { socket_address: { address: api-1, port_value: 8080 }}}
- endpoint: { address: { socket_address: { address: api-2, port_value: 8080 }}}
- endpoint: { address: { socket_address: { address: api-3, port_value: 8080 }}}
Three replicas of api, all in one (default) locality.
Take your envoy.yaml from the last lesson. Do three things:
-
Add a second cluster that points at a local nginx container — start one with
docker run --rm -p 8080:80 nginx. UseSTATICtype and addresshost.docker.internal(Mac/Windows) or your host's LAN IP (Linux). Or, if you're on Linux, run nginx with--network hostand use127.0.0.1. -
Run Envoy and visit
http://localhost:9901/clusters. You should see both clusters listed with their endpoints and health. -
Change the
httpbincluster type fromLOGICAL_DNStoSTRICT_DNSand reload. Confirm everything still works. Then change it toSTATICwithout changing the address — restart and watch it fail. Now you've proven the pitfall above.
Always set connect_timeout. Without it, Envoy will use a long
default and a single misbehaving endpoint can stall many in-flight
requests waiting for TCP handshake. 1s is a reasonable
starting point.
Up next
You've got listeners (Lesson 5) and clusters (this one). The piece in the middle — how a request finds the right cluster — is routes. That's the next lesson.
Which cluster `type` will resolve a hostname like `api.example.com` to its current IPs at runtime?