APISIX Service Discovery Guide

APISIX Service Discovery Overview

APISIX Service Discovery Architecture

Introduction

Service discovery is essential in modern microservices architectures. APISIX provides robust integration with various service discovery systems, enabling dynamic service registration and discovery.


Supported Service Discovery Systems

Consul Integration

Connect APISIX with HashiCorp Consul

discovery:
  consul:
    servers:
      - "http://127.0.0.1:8500"
    prefix: "upstreams"

Eureka Integration

Integration with Netflix Eureka

discovery:
  eureka:
    host:
      - "http://127.0.0.1:8761"
    prefix: "/eureka"

DNS Discovery

Use DNS for service discovery

discovery:
  dns:
    servers:
      - "8.8.8.8"
    order: ["AAAA", "A"]

Nacos Integration

Connect with Alibaba Nacos

discovery:
  nacos:
    host:
      - "http://127.0.0.1:8848"
    prefix: "/nacos"

Configuration Examples

Basic Service Discovery Setup

-- Enable service discovery in config.yaml
discovery:
  enable: true
  registry:
    consul:
      servers:
        - "http://consul:8500"

Route Configuration with Service Discovery

routes:
  - uri: "/api/*"
    upstream:
      service_name: "my-service"
      discovery_type: "consul"
      type: "roundrobin"
Note: Make sure your services are properly registered with the service discovery system before configuring APISIX routes.

Health Checks

Health Checks

Health Check Integration with Service Discovery

upstream:
  service_name: "my-service"
  discovery_type: "consul"
  checks:
    active:
      http_path: "/health"
      healthy:
        interval: 2
        successes: 1
      unhealthy:
        interval: 1
        http_failures: 2

Dynamic Updates

APISIX automatically updates its routing table when service instances change in the service discovery system.

-- Example of dynamic service update
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/api/*",
    "upstream": {
        "service_name": "my-service",
        "discovery_type": "consul",
        "type": "roundrobin"
    }
}'

Best Practices

  • Always configure health checks for reliable service discovery
  • Use appropriate timeouts for service discovery queries
  • Implement proper error handling for service discovery failures
  • Monitor service discovery metrics
  • Keep service discovery configurations consistent across environments
Pro Tip: Use service tags/metadata to implement fine-grained routing rules.

Troubleshooting

Common Issues and Solutions

  • Service not found in discovery system
  • Health check failures
  • Configuration synchronization issues
  • Network connectivity problems

Read Next

Load Balancing

Configure load balancing strategies

Read More

Logging

Set up comprehensive logging

Read More
Subscribe to Our Newsletter

Get the latest updates and exclusive content delivered to your inbox!