Files
easyai-ai-gateway/deploy/kubernetes/production/database.yaml
T
wangbo 8ef9de0b06 fix(cluster): 收敛宁波单实例数据库拓扑
将生产 CNPG 固定为宁波单实例,并显式关闭旧同步复制配置。发布流程在拓扑收敛前校验主库位置并创建 OSS 备份,应用后验证单实例、无复制连接和主库可用。同步更新生产监控、集群验收和发布脚本回归测试。
2026-08-04 23:24:37 +08:00

172 lines
4.8 KiB
YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: easyai-barman-aws-config
labels:
app.kubernetes.io/part-of: easyai-ai-gateway
data:
config: |
[default]
region = oss-cn-shanghai
s3 =
addressing_style = virtual
signature_version = s3
---
apiVersion: barmancloud.cnpg.io/v1
kind: ObjectStore
metadata:
name: easyai-postgres-oss
labels:
app.kubernetes.io/part-of: easyai-ai-gateway
spec:
retentionPolicy: 14d
configuration:
destinationPath: s3://wangbo0808/easyai-ai-gateway/production/postgresql
endpointURL: https://s3.oss-cn-shanghai.aliyuncs.com
s3Credentials:
accessKeyId:
name: easyai-oss-backup
key: ACCESS_KEY_ID
secretAccessKey:
name: easyai-oss-backup
key: ACCESS_SECRET_KEY
wal:
archiveAdditionalCommandArgs:
- --addressing-style=virtual
compression: gzip
maxParallel: 2
restoreAdditionalCommandArgs:
- --addressing-style=virtual
data:
additionalCommandArgs:
- --addressing-style=virtual
compression: gzip
jobs: 2
restoreAdditionalCommandArgs:
- --addressing-style=virtual
instanceSidecarConfiguration:
env:
- name: AWS_CONFIG_FILE
value: /projected/barman-aws/config
- name: AWS_DEFAULT_REGION
value: oss-cn-shanghai
- name: AWS_REQUEST_CHECKSUM_CALCULATION
value: when_required
- name: AWS_RESPONSE_CHECKSUM_VALIDATION
value: when_required
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: easyai-postgres
labels:
app.kubernetes.io/name: easyai-postgres
app.kubernetes.io/part-of: easyai-ai-gateway
spec:
# Production currently uses one Ningbo primary. Cross-region replicas are
# intentionally disabled until a separately certified HA topology exists.
instances: 1
imageName: ghcr.io/cloudnative-pg/postgresql:18.4-standard-trixie@sha256:4587df73024408f5b2be9b4dd6ba2ccee8c9e5dc0c9a87c274c292291cc8a68c
imagePullPolicy: IfNotPresent
env:
- name: KUBERNETES_SERVICE_HOST
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: KUBERNETES_SERVICE_PORT
value: "6443"
primaryUpdateStrategy: unsupervised
primaryUpdateMethod: switchover
failoverDelay: 0
switchoverDelay: 60
stopDelay: 90
smartShutdownTimeout: 30
livenessProbeTimeout: 300
probes:
liveness:
isolationCheck:
enabled: true
connectionTimeout: 5000
requestTimeout: 5000
bootstrap:
initdb:
database: easyai_ai_gateway
owner: easyai
secret:
name: easyai-postgres-app
postInitSQL:
- CREATE EXTENSION IF NOT EXISTS pgcrypto;
storage:
storageClass: local-path
size: 20Gi
walStorage:
storageClass: local-path
size: 5Gi
affinity:
enablePodAntiAffinity: true
podAntiAffinityType: required
topologyKey: easyai.io/site
nodeSelector:
easyai.io/database: "true"
easyai.io/site: ningbo
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: "2"
memory: 3Gi
postgresql:
# Keep this explicit null so server-side apply atomically removes the old
# two-instance synchronous setting during preflight field management.
synchronous: null
parameters:
# A 16 MiB WAL segment every 60 seconds requires at least 2.24 Mbit/s
# of continuous cross-region throughput even while the database is idle.
# The certified Ningbo/Hong Kong path is below that floor, so keep the
# object-storage RPO within five minutes without starving sync replay.
archive_timeout: 5min
max_connections: "200"
shared_buffers: 512MB
wal_compression: "on"
wal_keep_size: 1GB
# CNPG defaults these cross-region liveness timers to 5 seconds. A short
# control-plane or pod-network stall can otherwise tear down a future
# WAL stream. Keep failure detection bounded without amplifying a
# transient multi-second stall into repeated reconnects.
wal_sender_timeout: 30s
wal_receiver_timeout: 30s
monitoring:
enablePodMonitor: false
projectedVolumeTemplate:
defaultMode: 0444
sources:
- configMap:
name: easyai-barman-aws-config
items:
- key: config
path: barman-aws/config
plugins:
- name: barman-cloud.cloudnative-pg.io
isWALArchiver: true
parameters:
barmanObjectName: easyai-postgres-oss
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: easyai-postgres-daily
labels:
app.kubernetes.io/part-of: easyai-ai-gateway
spec:
# Six-field cron, UTC: 18:30 UTC is 02:30 Asia/Shanghai.
schedule: "0 30 18 * * *"
backupOwnerReference: self
cluster:
name: easyai-postgres
method: plugin
pluginConfiguration:
name: barman-cloud.cloudnative-pg.io
immediate: false
suspend: false