Service Discovery
Service discovery in API7 Gateway replaces static node lists with dynamic endpoint resolution. Instead of manually updating IP addresses for your upstream services, you can configure the data plane to query a service registry and automatically discover backend nodes.
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).
- 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 (in shared dictionaries like
kubernetesornacos) 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
API7 Gateway's 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.
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) |
| Scalability | Manual updates required on scaling | Instant scaling support |
| Environment | Bare metal, legacy apps | Kubernetes, microservices |
Configuration fields
When configuring an upstream with service discovery, you will typically provide:
- Service Name: The name of the service as registered in the registry (e.g.,
user-service.default.svc.cluster.local). - Discovery Type: The registry type (
kubernetesornacos). - Namespace Selector: For Kubernetes, filters which namespaces the gateway should monitor.
- Default Weight: The weight assigned to discovered nodes if not provided by the registry.
Next steps
- Upstreams and Load Balancing — configure backend targets and load balancing algorithms.
- Deploy on Kubernetes — deploy the gateway with Kubernetes service discovery.