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.
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.
- Query Registry: The data plane (DP) periodically queries the configured service registry (e.g., Kubernetes API, Nacos server, Consul agent).
- Retrieve Endpoints: The registry returns a list of healthy IP addresses and ports for the requested service.
- Local Cache: The DP caches these endpoints in memory for high-performance routing.
- Update Nodes: The DP updates the upstream node list based on the retrieved endpoints.
- 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
| Feature | Static Nodes | Service Discovery |
|---|---|---|
| Configuration | Manual (IP/Port) | Automated (Service Name) |
| Maintenance | High (must update on node change) | Low (automatic) |
| Scaling | Manual node updates required | Nodes follow the registry as it updates |
| Environment | Bare metal, legacy apps | Kubernetes, 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, orconsul). - 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.
Related
Tasks that use this concept
- Deploy on Kubernetes — deploy the gateway with Kubernetes service discovery.
Related concepts
- Upstreams and Load Balancing — configure backend targets and load balancing algorithms.