-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathload-balancer.kdl
More file actions
217 lines (185 loc) · 5.36 KB
/
load-balancer.kdl
File metadata and controls
217 lines (185 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Example: Load Balancer Configuration
//
// Traffic distribution across multiple backends with:
// - Multiple load balancing algorithms
// - Weighted round-robin
// - Health checks with ejection
// - Circuit breakers
// - Connection draining
system {
worker-threads 0
max-connections 20000
graceful-shutdown-timeout-secs 60
}
listeners {
listener "http" {
address "0.0.0.0:8080"
protocol "http"
request-timeout-secs 60
}
}
// =============================================================================
// Routes
// =============================================================================
routes {
// Main application route
route "app" {
priority "normal"
matches {
path-prefix "/"
}
upstream "app-cluster"
circuit-breaker {
failure-threshold 5
success-threshold 2
timeout-seconds 60
half-open-max-requests 3
}
retry-policy {
max-attempts 3
timeout-ms 10000
backoff-base-ms 100
retryable-status-codes 502 503 504
}
policies {
timeout-secs 30
failure-mode "open"
}
}
// Health check
route "health" {
priority "critical"
matches {
path "/health"
}
builtin-handler "health"
}
// Upstream status endpoint
route "upstream-status" {
priority "critical"
matches {
path "/upstream-status"
}
builtin-handler "health"
}
}
// =============================================================================
// Upstreams with different load balancing strategies
// =============================================================================
upstreams {
// Primary cluster with weighted round-robin
upstream "app-cluster" {
// Weights determine traffic distribution
target "10.0.1.10:3000" weight=100
target "10.0.1.11:3000" weight=100
target "10.0.1.12:3000" weight=100
target "10.0.1.13:3000" weight=50 // Lower capacity node
target "10.0.1.14:3000" weight=50 // Lower capacity node
load-balancing "weighted-round-robin"
health-check {
type "http" {
path "/health"
expected-status 200
}
interval-secs 5
timeout-secs 3
healthy-threshold 2
unhealthy-threshold 3
}
connection-pool {
max-connections 100
max-idle 20
idle-timeout-secs 60
}
timeouts {
connect-secs 5
request-secs 30
read-secs 30
}
}
// Least connections - good for varying request durations
upstream "app-least-conn" {
target "10.0.2.10:3000" weight=1
target "10.0.2.11:3000" weight=1
target "10.0.2.12:3000" weight=1
load-balancing "least-connections"
health-check {
type "http" {
path "/health"
}
interval-secs 5
timeout-secs 3
healthy-threshold 2
unhealthy-threshold 3
}
}
// IP hash - session affinity
upstream "app-sticky" {
target "10.0.3.10:3000" weight=1
target "10.0.3.11:3000" weight=1
load-balancing "ip-hash"
health-check {
type "http" {
path "/health"
}
interval-secs 10
timeout-secs 5
healthy-threshold 2
unhealthy-threshold 3
}
}
}
// =============================================================================
// Blue-Green Deployment Example
// =============================================================================
// To switch traffic between blue and green:
// 1. Update the route to point to the other upstream
// 2. Hot-reload the configuration
// Blue environment
// upstream "app-blue" {
// target "10.0.10.10:3000" weight=1
// target "10.0.10.11:3000" weight=1
// load-balancing "round-robin"
// }
// Green environment
// upstream "app-green" {
// target "10.0.20.10:3000" weight=1
// target "10.0.20.11:3000" weight=1
// load-balancing "round-robin"
// }
// =============================================================================
// Canary Deployment Example
// =============================================================================
// upstream "app-canary" {
// // Stable (90% traffic)
// target "10.0.1.10:3000" weight=90
// target "10.0.1.11:3000" weight=90
// // Canary (10% traffic)
// target "10.0.2.10:3000" weight=10
//
// load-balancing "weighted-round-robin"
// }
// =============================================================================
// Observability
// =============================================================================
observability {
metrics {
enabled #true
address "0.0.0.0:9090"
path "/metrics"
// Key metrics:
// - zentinel_upstream_health (per target)
// - zentinel_upstream_requests_total
// - zentinel_upstream_latency_seconds
// - zentinel_circuit_breaker_state
}
logging {
level "info"
format "json"
}
}
limits {
max-header-size-bytes 8192
max-header-count 100
max-body-size-bytes 10485760
}