Appearance
Service Discovery
Kubernetes (Default)
In Kubernetes, APISIX discovers upstreams via DNS automatically. Each service gets a ClusterIP DNS name:
yaml
# APISIX upstream config
upstream:
type: roundrobin
nodes:
ai-gateway.gatez.svc.cluster.local:4000: 1APISIX resolves ai-gateway.gatez.svc.cluster.local via CoreDNS. No additional configuration needed.
Headless Services (Pod-level routing)
For direct pod routing (bypassing ClusterIP load balancing):
yaml
apiVersion: v1
kind: Service
metadata:
name: ai-gateway-headless
namespace: gatez
spec:
clusterIP: None
selector:
app: ai-gateway
ports:
- port: 4000APISIX resolves headless services to individual pod IPs, enabling pod-level health checks.
Consul Integration
APISIX supports Consul for service discovery via the consul discovery module:
yaml
# apisix.yaml
discovery:
consul:
servers:
- "http://consul:8500"
prefix: "/v1/health/service"
weight: 1
fetch_interval: 3
default_service:
host: "127.0.0.1"
port: 80Register services in Consul:
bash
curl -X PUT http://consul:8500/v1/agent/service/register -d '{
"ID": "ai-gateway-1",
"Name": "ai-gateway",
"Port": 4000,
"Check": {"HTTP": "http://localhost:4000/health", "Interval": "10s"}
}'DNS SRV Records
APISIX supports DNS SRV record-based discovery:
yaml
# apisix.yaml
discovery:
dns:
servers:
- "127.0.0.1:53"yaml
# APISIX route with DNS discovery
upstream:
discovery_type: dns
service_name: _ai-gateway._tcp.gatez.svc.cluster.localDocker Compose (Development)
In Docker Compose, services discover each other via container names on the gateway-net network:
yaml
upstream:
nodes:
ai-gateway:4000: 1 # Container name resolution
agent-gateway:5000: 1
mock-backend:80: 1No additional discovery configuration needed for development.