feat(deploy): add pgbouncer poolers
This commit is contained in:
@@ -54,6 +54,12 @@ services:
|
||||
monitoring-postgres:
|
||||
pull_policy: never
|
||||
|
||||
pgbouncer:
|
||||
pull_policy: never
|
||||
|
||||
monitoring-pgbouncer:
|
||||
pull_policy: never
|
||||
|
||||
rabbitmq:
|
||||
pull_policy: never
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ name: geo-rankly
|
||||
|
||||
x-app-env: &app-env
|
||||
CONFIG_PATH: /app/configs/config.yaml
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
JWT_SECRET: ${JWT_SECRET:-geo-Aa123456-change-me-in-production}
|
||||
JWT_ACCESS_TTL: ${JWT_ACCESS_TTL:-15m}
|
||||
JWT_REFRESH_TTL: ${JWT_REFRESH_TTL:-720h}
|
||||
@@ -23,9 +24,9 @@ x-app-volumes: &app-volumes
|
||||
- ./prompts.yml:/app/configs/prompts.yml:ro
|
||||
|
||||
x-app-depends: &app-depends
|
||||
postgres:
|
||||
pgbouncer:
|
||||
condition: service_healthy
|
||||
monitoring-postgres:
|
||||
monitoring-pgbouncer:
|
||||
condition: service_healthy
|
||||
rabbitmq:
|
||||
condition: service_healthy
|
||||
@@ -49,7 +50,7 @@ services:
|
||||
environment:
|
||||
POSTGRES_DB: geo
|
||||
POSTGRES_USER: geo
|
||||
POSTGRES_PASSWORD: geo_dev
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
@@ -65,7 +66,7 @@ services:
|
||||
environment:
|
||||
POSTGRES_DB: geo_monitoring
|
||||
POSTGRES_USER: geo
|
||||
POSTGRES_PASSWORD: geo_dev
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
volumes:
|
||||
- monitoring_pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
@@ -74,6 +75,72 @@ services:
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
pgbouncer:
|
||||
image: edoburu/pgbouncer:v1.24.1-p1
|
||||
container_name: geo-pgbouncer
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
DB_HOST: postgres
|
||||
DB_PORT: 5432
|
||||
DB_USER: geo
|
||||
DB_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
DB_NAME: geo
|
||||
AUTH_TYPE: scram-sha-256
|
||||
POOL_MODE: session
|
||||
MAX_CLIENT_CONN: 200
|
||||
DEFAULT_POOL_SIZE: 30
|
||||
MIN_POOL_SIZE: 2
|
||||
RESERVE_POOL_SIZE: 5
|
||||
RESERVE_POOL_TIMEOUT: 5
|
||||
SERVER_IDLE_TIMEOUT: 60
|
||||
SERVER_LIFETIME: 1800
|
||||
SERVER_CONNECT_TIMEOUT: 15
|
||||
CLIENT_LOGIN_TIMEOUT: 15
|
||||
IGNORE_STARTUP_PARAMETERS: extra_float_digits
|
||||
ADMIN_USERS: geo
|
||||
STATS_USERS: geo
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "PGPASSWORD=\"$${DB_PASSWORD}\" psql -h 127.0.0.1 -p 5432 -U geo -d geo -c 'SELECT 1' >/dev/null"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
monitoring-pgbouncer:
|
||||
image: edoburu/pgbouncer:v1.24.1-p1
|
||||
container_name: geo-monitoring-pgbouncer
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
monitoring-postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
DB_HOST: monitoring-postgres
|
||||
DB_PORT: 5432
|
||||
DB_USER: geo
|
||||
DB_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
DB_NAME: geo_monitoring
|
||||
AUTH_TYPE: scram-sha-256
|
||||
POOL_MODE: session
|
||||
MAX_CLIENT_CONN: 200
|
||||
DEFAULT_POOL_SIZE: 30
|
||||
MIN_POOL_SIZE: 2
|
||||
RESERVE_POOL_SIZE: 5
|
||||
RESERVE_POOL_TIMEOUT: 5
|
||||
SERVER_IDLE_TIMEOUT: 60
|
||||
SERVER_LIFETIME: 1800
|
||||
SERVER_CONNECT_TIMEOUT: 15
|
||||
CLIENT_LOGIN_TIMEOUT: 15
|
||||
IGNORE_STARTUP_PARAMETERS: extra_float_digits
|
||||
ADMIN_USERS: geo
|
||||
STATS_USERS: geo
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "PGPASSWORD=\"$${DB_PASSWORD}\" psql -h 127.0.0.1 -p 5432 -U geo -d geo_monitoring -c 'SELECT 1' >/dev/null"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3.13-management-alpine
|
||||
container_name: geo-rabbitmq
|
||||
@@ -161,9 +228,10 @@ services:
|
||||
- ./prompts.yml:/app/configs/prompts.yml:ro
|
||||
entrypoint: >
|
||||
/bin/sh -c "
|
||||
/usr/local/bin/migrate -path /migrations -database 'postgres://geo:geo_dev@postgres:5432/geo?sslmode=disable' up &&
|
||||
/usr/local/bin/migrate -path /migrations_monitoring -database 'postgres://geo:geo_dev@monitoring-postgres:5432/geo_monitoring?sslmode=disable' up &&
|
||||
/usr/local/bin/migrate -path /migrations_ops -database 'postgres://geo:geo_dev@postgres:5432/geo?sslmode=disable&x-migrations-table=schema_migrations_ops' up &&
|
||||
export PGPASSWORD='$${POSTGRES_PASSWORD:-geo_dev}' &&
|
||||
/usr/local/bin/migrate -path /migrations -database 'postgres://geo@postgres:5432/geo?sslmode=disable' up &&
|
||||
/usr/local/bin/migrate -path /migrations_monitoring -database 'postgres://geo@monitoring-postgres:5432/geo_monitoring?sslmode=disable' up &&
|
||||
/usr/local/bin/migrate -path /migrations_ops -database 'postgres://geo@postgres:5432/geo?sslmode=disable&x-migrations-table=schema_migrations_ops' up &&
|
||||
/usr/local/bin/seed-platform-templates
|
||||
"
|
||||
restart: "no"
|
||||
@@ -250,6 +318,8 @@ services:
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
CONFIG_PATH: /app/configs/ops-config.yaml
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
OPS_POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-geo_dev}
|
||||
OPS_JWT_SECRET: ${OPS_JWT_SECRET:-change-me-in-production}
|
||||
OPS_DEFAULT_ADMIN_USERNAME: ${OPS_DEFAULT_ADMIN_USERNAME:-admin}
|
||||
OPS_DEFAULT_ADMIN_PASSWORD: ${OPS_DEFAULT_ADMIN_PASSWORD:-}
|
||||
@@ -258,9 +328,9 @@ services:
|
||||
volumes:
|
||||
- ./ops-config.yaml:/app/configs/ops-config.yaml:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
pgbouncer:
|
||||
condition: service_healthy
|
||||
monitoring-postgres:
|
||||
monitoring-pgbouncer:
|
||||
condition: service_healthy
|
||||
migrate:
|
||||
condition: service_completed_successfully
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: pgbouncer
|
||||
labels:
|
||||
app.kubernetes.io/name: pgbouncer
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/name: pgbouncer
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
targetPort: postgres
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pgbouncer
|
||||
labels:
|
||||
app.kubernetes.io/name: pgbouncer
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: pgbouncer
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: pgbouncer
|
||||
spec:
|
||||
containers:
|
||||
- name: pgbouncer
|
||||
image: edoburu/pgbouncer:v1.24.1-p1
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- name: postgres
|
||||
containerPort: 5432
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: postgres
|
||||
- name: DB_PORT
|
||||
value: "5432"
|
||||
- name: DB_USER
|
||||
value: geo
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: geo-rankly-app-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: DB_NAME
|
||||
value: geo
|
||||
- name: AUTH_TYPE
|
||||
value: scram-sha-256
|
||||
- name: POOL_MODE
|
||||
value: session
|
||||
- name: MAX_CLIENT_CONN
|
||||
value: "200"
|
||||
- name: DEFAULT_POOL_SIZE
|
||||
value: "30"
|
||||
- name: MIN_POOL_SIZE
|
||||
value: "2"
|
||||
- name: RESERVE_POOL_SIZE
|
||||
value: "5"
|
||||
- name: RESERVE_POOL_TIMEOUT
|
||||
value: "5"
|
||||
- name: SERVER_IDLE_TIMEOUT
|
||||
value: "60"
|
||||
- name: SERVER_LIFETIME
|
||||
value: "1800"
|
||||
- name: SERVER_CONNECT_TIMEOUT
|
||||
value: "15"
|
||||
- name: CLIENT_LOGIN_TIMEOUT
|
||||
value: "15"
|
||||
- name: IGNORE_STARTUP_PARAMETERS
|
||||
value: extra_float_digits
|
||||
- name: ADMIN_USERS
|
||||
value: geo
|
||||
- name: STATS_USERS
|
||||
value: geo
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -ec
|
||||
- PGPASSWORD="${DB_PASSWORD}" psql -h 127.0.0.1 -p 5432 -U geo -d geo -c 'SELECT 1' >/dev/null
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 5
|
||||
livenessProbe:
|
||||
exec:
|
||||
command: ["pg_isready", "-h", "127.0.0.1", "-p", "5432", "-U", "geo", "-d", "geo"]
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: monitoring-pgbouncer
|
||||
labels:
|
||||
app.kubernetes.io/name: monitoring-pgbouncer
|
||||
spec:
|
||||
selector:
|
||||
app.kubernetes.io/name: monitoring-pgbouncer
|
||||
ports:
|
||||
- name: postgres
|
||||
port: 5432
|
||||
targetPort: postgres
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: monitoring-pgbouncer
|
||||
labels:
|
||||
app.kubernetes.io/name: monitoring-pgbouncer
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: monitoring-pgbouncer
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app.kubernetes.io/name: monitoring-pgbouncer
|
||||
spec:
|
||||
containers:
|
||||
- name: pgbouncer
|
||||
image: edoburu/pgbouncer:v1.24.1-p1
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- name: postgres
|
||||
containerPort: 5432
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: monitoring-postgres
|
||||
- name: DB_PORT
|
||||
value: "5432"
|
||||
- name: DB_USER
|
||||
value: geo
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: geo-rankly-app-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: DB_NAME
|
||||
value: geo_monitoring
|
||||
- name: AUTH_TYPE
|
||||
value: scram-sha-256
|
||||
- name: POOL_MODE
|
||||
value: session
|
||||
- name: MAX_CLIENT_CONN
|
||||
value: "200"
|
||||
- name: DEFAULT_POOL_SIZE
|
||||
value: "30"
|
||||
- name: MIN_POOL_SIZE
|
||||
value: "2"
|
||||
- name: RESERVE_POOL_SIZE
|
||||
value: "5"
|
||||
- name: RESERVE_POOL_TIMEOUT
|
||||
value: "5"
|
||||
- name: SERVER_IDLE_TIMEOUT
|
||||
value: "60"
|
||||
- name: SERVER_LIFETIME
|
||||
value: "1800"
|
||||
- name: SERVER_CONNECT_TIMEOUT
|
||||
value: "15"
|
||||
- name: CLIENT_LOGIN_TIMEOUT
|
||||
value: "15"
|
||||
- name: IGNORE_STARTUP_PARAMETERS
|
||||
value: extra_float_digits
|
||||
- name: ADMIN_USERS
|
||||
value: geo
|
||||
- name: STATS_USERS
|
||||
value: geo
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -ec
|
||||
- PGPASSWORD="${DB_PASSWORD}" psql -h 127.0.0.1 -p 5432 -U geo -d geo_monitoring -c 'SELECT 1' >/dev/null
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 5
|
||||
livenessProbe:
|
||||
exec:
|
||||
command: ["pg_isready", "-h", "127.0.0.1", "-p", "5432", "-U", "geo", "-d", "geo_monitoring"]
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
@@ -8,6 +8,7 @@ resources:
|
||||
- secrets.yaml
|
||||
- infra-postgres.yaml
|
||||
- infra-monitoring-postgres.yaml
|
||||
- infra-pgbouncer.yaml
|
||||
- infra-rabbitmq.yaml
|
||||
- infra-redis.yaml
|
||||
- infra-qdrant-minio.yaml
|
||||
|
||||
@@ -108,6 +108,7 @@ fi
|
||||
echo "==> [2/5] 拉取基础设施镜像 (platform: ${PLATFORM})"
|
||||
INFRA_IMAGES=(
|
||||
"postgres:16-alpine"
|
||||
"edoburu/pgbouncer:v1.24.1-p1"
|
||||
"rabbitmq:3.13-management-alpine"
|
||||
"redis:7-alpine"
|
||||
"qdrant/qdrant:v1.13.2"
|
||||
@@ -134,6 +135,7 @@ ALL_IMAGES=(
|
||||
"${LOCAL_PREFIX}/frontend:${IMAGE_TAG}"
|
||||
"${LOCAL_PREFIX}/ops-web:${IMAGE_TAG}"
|
||||
"postgres:16-alpine"
|
||||
"edoburu/pgbouncer:v1.24.1-p1"
|
||||
"rabbitmq:3.13-management-alpine"
|
||||
"redis:7-alpine"
|
||||
"qdrant/qdrant:v1.13.2"
|
||||
|
||||
Reference in New Issue
Block a user