Docs

Service Discovery

Dynamic upstream resolution in API7 Gateway — automatically discover backend endpoints from Kubernetes Services, Nacos, and Consul registries without hardcoding IPs.

Service discovery in API7 Gateway replaces static node lists with dynamic endpoint resolution. Instead of updating IP addresses for your upstream services by hand, configure the data plane to query a service registry and discover backend nodes automatically.

Query

Endpoint List

Update

Distribute

Service Registry: K8s / Nacos / Consul

Data Plane

Upstream Nodes

Load Balancer

Query

Endpoint List

Update

Distribute

Service Registry: K8s / Nacos / Consul

Data Plane

Upstream Nodes

Load Balancer

How service discovery works

When you use service discovery, you specify a Service Name and a Discovery Type in the upstream configuration instead of a static nodes array.

  1. Query Registry: The data plane (DP) periodically queries the configured service registry (e.g., Kubernetes API, Nacos server, Consul agent).
  2. Retrieve Endpoints: The registry returns a list of healthy IP addresses and ports for the requested service.
  3. Local Cache: The DP caches these endpoints in memory for high-performance routing.
  4. Update Nodes: The DP updates the upstream node list based on the retrieved endpoints.
  5. Load Balance: The gateway's load balancer distributes incoming requests across the discovered nodes.

Supported discovery types

The API7 Gateway control plane lets you connect services to the following service registries:

  • Kubernetes: Resolves endpoints for Kubernetes Services by querying the API server directly.
  • Nacos: Integrates with the Alibaba Nacos registry for dynamic service discovery.
  • Consul: Integrates with the HashiCorp Consul catalog for dynamic service discovery.

Comparison: Static nodes vs. service discovery

FeatureStatic NodesService Discovery
ConfigurationManual (IP/Port)Automated (Service Name)
MaintenanceHigh (must update on node change)Low (automatic)
ScalingManual node updates requiredNodes follow the registry as it updates
EnvironmentBare metal, legacy appsKubernetes, microservices

Configuration fields

When you configure an upstream with service discovery, provide:

  • Service name: The service identifier as registered in the registry. The expected format depends on the registry — for example, a Nacos-backed registry expects <registry_id>/<namespace>/<group>/<service_name> (e.g., <registry_id>/public/group/httpbin), not a Kubernetes-style DNS name.
  • Discovery type: The registry type (kubernetes, nacos, or consul).
  • Namespace selector: For Kubernetes, filters which namespaces the gateway monitors.
  • Default weight: The weight assigned to discovered nodes if the registry does not provide one.

Tasks that use this concept

Related concepts