kine pgx multi-host 직결: HAProxy 의존 제거, API 다운타임 <1s

This commit is contained in:
heimdall
2026-04-16 12:34:53 +09:00
parent 33ce94a75a
commit 226b377387
2 changed files with 67 additions and 18 deletions

View File

@@ -83,35 +83,26 @@ incus exec postgres-1 -- etcdctl --endpoints=http://192.168.9.100:2379,http://10
## K3s kine 연결
K3s → HAProxy(OpenWrt 192.168.9.1:5432) → Patroni Leader PostgreSQL
K3s → **pgx multi-host** → Patroni 3노드 직결 (HAProxy 미경유).
kine 은 `github.com/jackc/pgx/v5` 드라이버 사용 — libpq 호환 multi-host + `target_session_attrs=read-write` 지원. Patroni failover 시 pgx 가 자동으로 새 primary 에 재연결 (API 다운타임 <1초).
### K3s config
```yaml
# /etc/rancher/k3s/config.yaml (kr1, kr2)
datastore-endpoint: "postgres://kine:kine@192.168.9.1:5432/kine"
datastore-endpoint: "postgres://kine:kine@10.100.2.5:5432,10.100.3.185:5432,10.100.1.83:5432/kine?target_session_attrs=read-write&sslmode=disable"
```
### HAProxy (OpenWrt)
이전 구성 (HAProxy 경유, 2026-04-16 폐기): `postgres://kine:kine@192.168.9.1:5432/kine`
`/etc/haproxy.cfg`에 PostgreSQL backend 설정. Patroni REST API(`/primary` 엔드포인트)로 Leader를 자동 감지.
### 검증 (2026-04-16)
```
frontend ft_postgres
bind :5432
default_backend bk_postgres_primary
kr2 → kr1 순서로 rolling restart. switchover (postgres-1→postgres-3, TL12→13) 시 kine API 다운타임 **<1초** (t+2ms 에 정상 응답). [[../history/2026-04-16-kine-multihost-migration|history]]
backend bk_postgres_primary
option httpchk GET /primary
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server postgres-1 10.100.2.5:5432 check port 8008
server postgres-2 10.100.3.185:5432 check port 8008
server postgres-3 10.100.1.83:5432 check port 8008
```
### OpenWrt HAProxy :5432 프론트엔드
- Patroni failover 시 HAProxy가 자동으로 새 Leader를 감지 (~3초)
- K3s config 변경 없이 Leader 전환 대응
kine + pgpool 전환 완료로 HAProxy postgres 프론트엔드는 **더 이상 트래픽 없음**. 1주 관측 후 제거 예정.
## 애플리케이션 접속 경로 — pgpool-II