add CloudNativePG operator and HA postgres cluster

This commit is contained in:
Sergei Poljanski 2026-04-04 17:07:41 +03:00
commit 2a5ddda96c
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
6 changed files with 116 additions and 0 deletions

20
apps/cnpg-operator.yaml Normal file
View file

@ -0,0 +1,20 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: cnpg-operator
namespace: argocd
spec:
project: default
source:
repoURL: https://cloudnative-pg.github.io/charts
chart: cloudnative-pg
targetRevision: 0.28.0
destination:
server: https://kubernetes.default.svc
namespace: cnpg-system
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true

20
apps/postgres.yaml Normal file
View file

@ -0,0 +1,20 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: postgres
namespace: argocd
spec:
project: default
source:
repoURL: ssh://git@git.czsk.it/asxpi/k8s-asxpio-gitops.git
targetRevision: main
path: apps/postgres
destination:
server: https://kubernetes.default.svc
namespace: postgres
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true

View file

@ -0,0 +1,23 @@
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres-cluster
namespace: postgres
spec:
instances: 2
primaryUpdateStrategy: unsupervised
enableSuperuserAccess: true
postgresql:
parameters:
shared_buffers: "256MB"
max_connections: "200"
storage:
size: 10Gi
storageClass: hcloud-volumes
affinity:
enablePodAntiAffinity: true
topologyKey: kubernetes.io/hostname

View file

@ -0,0 +1,10 @@
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: watchparty-db
namespace: postgres
spec:
name: watchparty
owner: app
cluster:
name: postgres-cluster

View file

@ -24,6 +24,13 @@ spec:
value: "8080"
- name: HOST
value: "0.0.0.0"
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-cluster-app
key: password
- name: DATABASE_URL
value: postgresql://app:$(PG_PASSWORD)@postgres-cluster-rw.postgres.svc.cluster.local:5432/watchparty
resources:
requests:
memory: 256Mi