Skip to content

Commit 0cdf42c

Browse files
Fix envoy configuration for gateway high availability (#131)
* envoy admin, experiments * nginx, further experiments * envoy sticky sessions * configure hc timings for all timing paths * leave jitter settings unmodified * cleanup
1 parent eedb7be commit 0cdf42c

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

docker-compose2.0/docker-compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,31 @@ services:
6868

6969
gateway-lb:
7070
image: envoyproxy/envoy:v1.33-latest
71+
command: ["envoy", "-c", "/etc/envoy/envoy.yaml", "-l", "debug"]
7172
ports:
7273
- "50051:50051/udp"
74+
- "9901:9901"
7375
volumes:
7476
- ./envoy/envoy.yaml:/etc/envoy/envoy.yaml:ro
7577
depends_on:
7678
- gateway1
7779
- gateway2
7880

81+
# NGINX can be used for LB but not HA since it does not support healthchecks
82+
# gateway-lb-nginx:
83+
# image: nginx:1.25-alpine
84+
# command:
85+
# - /bin/sh
86+
# - -ec
87+
# - until getent hosts gateway1 gateway2 >/dev/null 2>&1; do sleep 0.2; done; exec nginx -g 'daemon off;'
88+
# ports:
89+
# - "50051:50051/udp"
90+
# volumes:
91+
# - ./nginx/gateway-lb.conf:/etc/nginx/nginx.conf:ro
92+
# depends_on:
93+
# - gateway1
94+
# - gateway2
95+
7996
db:
8097
image: postgres:18-alpine
8198
environment:

docker-compose2.0/envoy/envoy.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
admin:
2+
address:
3+
socket_address:
4+
address: 0.0.0.0
5+
port_value: 9901
6+
17
static_resources:
28
listeners:
39
- name: udp_listener
@@ -19,20 +25,27 @@ static_resources:
1925
"@type": type.googleapis.com/envoy.extensions.filters.udp.udp_proxy.v3.UdpProxyConfig
2026
stat_prefix: udp_lb
2127
cluster: defguard_gateway_cluster
28+
hash_policies:
29+
- source_ip: true
2230
idle_timeout: 60s
2331

2432
clusters:
2533
- name: defguard_gateway_cluster
2634
type: STRICT_DNS
2735
connect_timeout: 1s
28-
lb_policy: ROUND_ROBIN
36+
lb_policy: RING_HASH
2937
dns_lookup_family: V4_ONLY
3038

3139
health_checks:
32-
- timeout: 2s
33-
interval: 5s
34-
unhealthy_threshold: 2
35-
healthy_threshold: 2
40+
- timeout: 1s
41+
interval: 1s
42+
no_traffic_interval: 1s
43+
no_traffic_healthy_interval: 1s
44+
unhealthy_interval: 1s
45+
healthy_edge_interval: 1s
46+
unhealthy_edge_interval: 1s
47+
unhealthy_threshold: 1
48+
healthy_threshold: 1
3649
http_health_check:
3750
path: /health
3851
host: gateway_health
@@ -57,4 +70,4 @@ static_resources:
5770
address: gateway2
5871
port_value: 50051
5972
health_check_config:
60-
port_value: 55003
73+
port_value: 55003
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
worker_processes auto;
2+
3+
error_log /dev/stderr info;
4+
pid /tmp/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
stream {
11+
log_format udp '$remote_addr:$remote_port [$time_local] '
12+
'$protocol $status bytes_sent=$bytes_sent bytes_received=$bytes_received '
13+
'session_time=$session_time upstream=$upstream_addr';
14+
15+
access_log /dev/stdout udp;
16+
17+
upstream defguard_gateways_udp {
18+
server gateway1:50051 max_fails=1 fail_timeout=1s;
19+
server gateway2:50051 max_fails=1 fail_timeout=1s;
20+
}
21+
22+
server {
23+
listen 50051 udp reuseport;
24+
proxy_pass defguard_gateways_udp;
25+
proxy_connect_timeout 1s;
26+
proxy_timeout 60s;
27+
}
28+
}

0 commit comments

Comments
 (0)