kine pgx multi-host 직결: HAProxy 의존 제거, API 다운타임 <1s
This commit is contained in:
58
history/2026-04-16-kine-multihost-migration.md
Normal file
58
history/2026-04-16-kine-multihost-migration.md
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
date: 2026-04-16
|
||||
topic: kine pgx multi-host 직결 (HAProxy 의존 제거)
|
||||
areas:
|
||||
- infra/postgresql-ha.md
|
||||
tags: [history, k3s, kine, pgx, patroni, postgresql, migration]
|
||||
---
|
||||
|
||||
K3s kine 의 `datastore-endpoint` 를 HAProxy `192.168.9.1:5432` 에서 Patroni 3노드 pgx multi-host 로 전환. API 다운타임 <1초.
|
||||
|
||||
## 변경 사항
|
||||
|
||||
### K3s config (`/etc/rancher/k3s/config.yaml`, kr1 + kr2)
|
||||
|
||||
before:
|
||||
```yaml
|
||||
datastore-endpoint: "postgres://kine:kine@192.168.9.1:5432/kine"
|
||||
```
|
||||
|
||||
after:
|
||||
```yaml
|
||||
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"
|
||||
```
|
||||
|
||||
### 실행 순서
|
||||
|
||||
1. **kr2** (init server): config backup → sed 치환 → `systemctl restart k3s` → kubectl get nodes 확인 (5초 내 Ready)
|
||||
2. **kr1** (secondary server): 동일 → 10초 내 Ready
|
||||
3. 4노드 전체 Ready 확인 (hp1, hp2, kr1, kr2), API 응답 시간 ~200ms
|
||||
|
||||
### Patroni switchover 테스트
|
||||
|
||||
`patronictl switchover --leader postgres-1 --candidate postgres-3 --force` (TL12→13):
|
||||
|
||||
- switchover 커맨드 반환: 4.8초
|
||||
- kubectl get nodes 첫 응답: **t+2ms** (즉시) — `incus-hp1 Ready`
|
||||
- API 정상 응답 시간: 231ms
|
||||
- **API 다운타임: <1초**
|
||||
|
||||
kine 의 pgx `target_session_attrs=read-write` 가 자동으로 새 primary (postgres-3, 10.100.1.83) 에 재연결.
|
||||
|
||||
비교: HAProxy 경유 시 health check `inter 3s fall 3` = 최대 9초 감지 지연. pgx multi-host 방식은 connection-level 에서 즉시 재시도.
|
||||
|
||||
## 롤백
|
||||
|
||||
```bash
|
||||
sudo cp /tmp/config.yaml-backup-20260416 /etc/rancher/k3s/config.yaml
|
||||
sudo systemctl restart k3s
|
||||
```
|
||||
|
||||
## HAProxy :5432 상태
|
||||
|
||||
kine + pgpool(NocoDB/n8n/Outline) 전환 완료로 HAProxy postgres 프론트엔드 (`ft_postgres` + `bk_postgres_primary`) 는 더 이상 트래픽 없음. 1주 관측 후 제거.
|
||||
|
||||
## 참조
|
||||
|
||||
- `infra/postgresql-ha.md` — 「K3s kine 연결」 갱신
|
||||
- kine pgx 지원 확인: `k3s-io/kine` go.mod `github.com/jackc/pgx/v5`
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user