跳转到内容

Upstreams & Targets

此内容尚不支持你的语言。

Upstreams are backend server pools. Targets are individual servers within an upstream.

interface Upstream {
id: string;
name: string;
algorithm?: string; // Load balancing algorithm
hashOn?: string; // Hash input for hash algorithm
slots?: number; // Consistent hash slots
healthcheck?: object; // Health check config
tags?: string[];
}
interface Target {
id: string;
upstreamId: string;
target: string; // URL or IP:port
weight?: number; // Weight for weighted algorithms
tags?: string[];
}

Distribute requests proportionally:

// Targets with weights
{ "target": "server-a", "weight": 3 }
{ "target": "server-b", "weight": 1 }

Distribution: A receives 75% of requests, B receives 25%.

Terminal window
curl http://localhost:8080/api/upstreams
Terminal window
curl http://localhost:8080/api/upstreams/upstream_abc123
Terminal window
curl -X PATCH http://localhost:8080/api/upstreams/upstream_abc123 \
-H "Content-Type: application/json" \
-d '{
"algorithm": "least-connections"
}'
Terminal window
curl -X DELETE http://localhost:8080/api/upstreams/upstream_abc123
Terminal window
curl http://localhost:8080/api/targets?upstreamId=upstream_abc123
Terminal window
curl -X PATCH http://localhost:8080/api/targets/target_xyz789 \
-H "Content-Type: application/json" \
-d '{
"weight": 5
}'
Terminal window
curl -X DELETE http://localhost:8080/api/targets/target_xyz789

Targets can use various formats:

Routes reference upstreams through service configuration:

  1. Create route pointing to service
  2. Service defines upstream connection
  3. Upstream provides targets