generated from nginxinc/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e9256f
commit 2452754
Showing
2 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# NGINX Loadbalancer for K8s HTTP configuration, for L7 load balancing | ||
# Chris Akker, Apr 2023 | ||
# HTTP Proxy and load balancing | ||
# MultiCluster Load Balancing with http split clients 0-100% | ||
# Upstream servers managed by NLK Controller | ||
# Nginx Key Value store for Split ratios | ||
# | ||
#### clusters.conf | ||
|
||
# Define Key Value store, backup state file, timeout, and enable sync | ||
|
||
keyval_zone zone=split:1m state=/var/lib/nginx/state/split.keyval timeout=30d sync; | ||
keyval $host $split_level zone=split; | ||
|
||
# Main Nginx Server Block for cafe.example.com, with TLS | ||
|
||
server { | ||
listen 443 ssl; | ||
status_zone https://cafe.example.com; | ||
server_name cafe.example.com; | ||
|
||
ssl_certificate /etc/ssl/nginx/default.crt; # self-signed for example only | ||
ssl_certificate_key /etc/ssl/nginx/default.key; | ||
|
||
location / { | ||
status_zone /; | ||
|
||
proxy_set_header Host $host; | ||
proxy_http_version 1.1; | ||
proxy_set_header "Connection" ""; | ||
proxy_pass https://$upstream; | ||
|
||
} | ||
|
||
location @health_check_cluster1_cafe { | ||
|
||
health_check interval=10 match=cafe; | ||
proxy_connect_timeout 2s; | ||
proxy_read_timeout 3s; | ||
proxy_set_header Host cafe.example.com; | ||
proxy_pass https://cluster1-https; | ||
} | ||
|
||
location @health_check_cluster2_cafe { | ||
|
||
health_check interval=10 match=cafe; | ||
proxy_connect_timeout 2s; | ||
proxy_read_timeout 3s; | ||
proxy_set_header Host cafe.example.com; | ||
proxy_pass https://cluster2-https; | ||
} | ||
} | ||
|
||
match cafe { | ||
status 200-399; | ||
} | ||
|
||
# Cluster1 upstreams | ||
|
||
upstream cluster1-https { | ||
zone cluster1-https 256k; | ||
least_time last_byte; | ||
keepalive 16; | ||
#servers managed by NLK Controller | ||
state /var/lib/nginx/state/cluster1-https.state; | ||
} | ||
|
||
# Cluster2 upstreams | ||
|
||
upstream cluster2-https { | ||
zone cluster2-https 256k; | ||
least_time last_byte; | ||
#servers managed by NLK Controller | ||
state /var/lib/nginx/state/cluster2-https.state; | ||
} | ||
|
||
# HTTP Split Clients Configuration for Cluster1/Cluster2 ratios | ||
|
||
split_clients $request_id $split0 { | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split1 { | ||
1.0% cluster1-https; | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split1000 { | ||
0.1% cluster1-https; | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split10000 { | ||
0.01% cluster1-https; | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split100000 { | ||
0.001% cluster1-https; | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split1000000 { | ||
0.0001% cluster1-https; | ||
* cluster2-https; | ||
} | ||
|
||
split_clients $request_id $split100 { | ||
* cluster1-https; | ||
} | ||
|
||
map $split_level $upstream { | ||
0 $split0; | ||
1.0 $split1; | ||
0.1 $split1000; | ||
0.01 $split10000; | ||
0.001 $split100000; | ||
0.0001 $split1000000; | ||
100 $split100; | ||
default $split50; | ||
} |