API Gateway
Apache APISIX configuration, routing, and plugins.
Overview
APISIX provides:
- Dynamic routing synchronized from Consul
- Authentication (JWT, API Key)
- Rate limiting and circuit breaking
- CORS and security headers
- SSL/TLS termination
- Prometheus metrics
Ports
| Port | Purpose |
|---|---|
| 9080 | HTTP Gateway |
| 9443 | HTTPS Gateway |
| 9180 | Admin API |
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β External Traffic β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β APISIX Gateway β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
β β Auth β β Rate β β CORS β β Logging β β
β β Plugin β β Limiter β β Plugin β β Plugin β β
β βββββββββββ βββββββββββ βββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Consul Service Discovery β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend Services β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββRoute Configuration
Create Route
curl -X PUT http://localhost:9180/apisix/admin/routes/1 \
-H "X-API-KEY: admin-key" \
-H "Content-Type: application/json" \
-d '{
"uri": "/api/v1/users/*",
"upstream": {
"type": "roundrobin",
"discovery_type": "consul",
"service_name": "auth_service"
},
"plugins": {
"jwt-auth": {},
"limit-req": {
"rate": 100,
"burst": 50
}
}
}'Route with Consul Discovery
routes:
- uri: /api/v1/auth/*
upstream:
discovery_type: consul
service_name: auth_service
plugins:
limit-req:
rate: 5
burst: 10
- uri: /api/v1/users/*
upstream:
discovery_type: consul
service_name: profile_service
plugins:
jwt-auth: {}Plugins
JWT Authentication
{
"plugins": {
"jwt-auth": {
"key": "user-key",
"secret": "your-secret"
}
}
}Rate Limiting
{
"plugins": {
"limit-req": {
"rate": 100,
"burst": 50,
"key_type": "consumer_name"
},
"limit-count": {
"count": 1000,
"time_window": 3600,
"key_type": "var",
"key": "remote_addr"
}
}
}CORS
{
"plugins": {
"cors": {
"allow_origins": "https://app.isa.io",
"allow_methods": "GET,POST,PUT,DELETE",
"allow_headers": "Authorization,Content-Type",
"max_age": 3600
}
}
}Rate Limits by Tier
| Endpoint Type | Rate | Burst |
|---|---|---|
| Public (login) | 5/min | 10 |
| Authenticated | 100/min | 200 |
| Admin | 1000/min | 500 |
| Internal | Unlimited | - |
Monitoring
Prometheus Metrics
curl http://localhost:9091/apisix/prometheus/metricsAvailable metrics:
apisix_http_status- HTTP status codesapisix_bandwidth- Bandwidth usageapisix_http_latency- Request latencyapisix_upstream_status- Upstream health
Admin API
List Routes
curl http://localhost:9180/apisix/admin/routes \
-H "X-API-KEY: admin-key"List Upstreams
curl http://localhost:9180/apisix/admin/upstreams \
-H "X-API-KEY: admin-key"Troubleshooting
Route Not Working
# Check route exists
curl http://localhost:9180/apisix/admin/routes/1 -H "X-API-KEY: admin-key"
# Check upstream health
curl http://localhost:9180/apisix/admin/upstreams/1 -H "X-API-KEY: admin-key"Service Not Found
# Verify Consul registration
curl http://localhost:8500/v1/catalog/service/auth_service
# Check APISIX logs
kubectl logs -l app=apisix -n isa-cloud-stagingNext Steps
- Discovery - Consul service discovery
- SDK - Client library
- Deployment - Production setup