envoy-guide
Module 2 · Your First Envoy·10 min·beginner

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

typeWhat endpoints look likeWhen to use
STATICLiteral IP:port pairsLocal testing, fixed infra
STRICT_DNSHostname → all A recordsService discovery via DNS
LOGICAL_DNSHostname → first valid record (lazy)Long-lived upstreams (e.g. external APIs)
EDSEndpoints arrive via xDSDynamic / service mesh (Istio uses this)

There's also ORIGINAL_DST for transparent proxies, which we'll skip.

STATIC + hostname = silent failure

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.

YAML
  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.

YAML
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.

Hands-on · Add a second cluster and switch DNS modes

Take your envoy.yaml from the last lesson. Do three things:

  1. Add a second cluster that points at a local nginx container — start one with docker run --rm -p 8080:80 nginx. Use STATIC type and address host.docker.internal (Mac/Windows) or your host's LAN IP (Linux). Or, if you're on Linux, run nginx with --network host and use 127.0.0.1.

  2. Run Envoy and visit http://localhost:9901/clusters. You should see both clusters listed with their endpoints and health.

  3. Change the httpbin cluster type from LOGICAL_DNS to STRICT_DNS and reload. Confirm everything still works. Then change it to STATIC without changing the address — restart and watch it fail. Now you've proven the pitfall above.

connect_timeout matters

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.

Real-world example · Stripe-style payment provider
Problem
The internal fraud-scoring service has 30 replicas across three availability zones. Endpoints come and go several times an hour as pods are rescheduled. A static config would be wrong within minutes.
Envoy solution
The cluster type is EDS. The control plane (Istio's istiod, or a custom xDS server) watches Kubernetes endpoints for the fraud-scoring service and streams updates to every Envoy. The data plane sees the endpoint set change live without restarts. Same cluster *shape* you wrote above — just with the endpoint list arriving over a gRPC stream instead of being typed into YAML.

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.

Quick check

Which cluster `type` will resolve a hostname like `api.example.com` to its current IPs at runtime?

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3