mirror of
https://github.com/auricom/home-cluster.git
synced 2025-09-17 18:24:14 +02:00
✨ cloudnative-pg migration
This commit is contained in:
@@ -5,5 +5,6 @@ kind: Kustomization
|
||||
namespace: default
|
||||
resources:
|
||||
- ./cluster16.yaml
|
||||
- ./pgdump
|
||||
- ./prometheusrule.yaml
|
||||
- ./scheduledbackup.yaml
|
||||
|
@@ -0,0 +1,25 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://kubernetes-schemas.devbu.io/external-secrets.io/externalsecret_v1beta1.json
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: cloudnative-pg-postgres16-pgdump
|
||||
namespace: default
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: onepassword-connect
|
||||
target:
|
||||
name: cloudnative-pg-postgres16-pgdump-secret
|
||||
template:
|
||||
engineVersion: v2
|
||||
data:
|
||||
# App
|
||||
POSTGRES_HOST: postgres16-rw.database.svc.cluster.local
|
||||
POSTGRES_USER: "{{ .POSTGRES_SUPER_USER }}"
|
||||
POSTGRES_PASSWORD: "{{ .POSTGRES_SUPER_PASS }}"
|
||||
POSTGRES_PORT: "5432"
|
||||
dataFrom:
|
||||
|
||||
- extract:
|
||||
key: cloudnative-pg
|
@@ -0,0 +1,104 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/helm.toolkit.fluxcd.io/helmrelease_v2beta2.json
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2beta2
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: cloudnative-pg-postgres16-pgdump
|
||||
namespace: default
|
||||
spec:
|
||||
interval: 30m
|
||||
chart:
|
||||
spec:
|
||||
chart: app-template
|
||||
version: 2.5.0
|
||||
sourceRef:
|
||||
kind: HelmRepository
|
||||
name: bjw-s
|
||||
namespace: flux-system
|
||||
maxHistory: 2
|
||||
install:
|
||||
createNamespace: true
|
||||
remediation:
|
||||
retries: 3
|
||||
upgrade:
|
||||
cleanupOnFail: true
|
||||
remediation:
|
||||
retries: 3
|
||||
uninstall:
|
||||
keepHistory: false
|
||||
values:
|
||||
controllers:
|
||||
main:
|
||||
type: cronjob
|
||||
cronjob:
|
||||
concurrencyPolicy: Forbid
|
||||
schedule: "@daily"
|
||||
initContainers:
|
||||
init-db:
|
||||
image:
|
||||
repository: ghcr.io/onedr0p/postgres-init
|
||||
tag: 16
|
||||
env:
|
||||
EXCLUDE_DBS: "home_assistant lidarr_log radarr_log sonarr_log prowlarr_log postgres template0 template1"
|
||||
envFrom: &envFrom
|
||||
- secretRef:
|
||||
name: cloudnative-pg-postgres16-pgdump-secret
|
||||
command:
|
||||
- "/bin/bash"
|
||||
- "-c"
|
||||
- |
|
||||
#!/bin/bash
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
|
||||
# File to store the list of databases
|
||||
OUTPUT_FILE="/config/db_list"
|
||||
|
||||
# Export PG password to avoid password prompt
|
||||
export PGPASSWORD=$POSTGRES_PASSWORD
|
||||
|
||||
# Generate a regex pattern for exclusion
|
||||
EXCLUDE_PATTERN=$(echo $EXCLUDE_DBS | sed 's/ /\\|/g')
|
||||
|
||||
# List all databases, exclude the ones in EXCLUDE_DBS, and write to the file
|
||||
psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -lqt | \
|
||||
cut -d \| -f 1 | \
|
||||
grep -Ev "^\s*($EXCLUDE_PATTERN)\s*$" > "$OUTPUT_FILE"
|
||||
|
||||
# Unset PG password
|
||||
unset PGPASSWORD
|
||||
|
||||
echo "Database list saved to $OUTPUT_FILE"
|
||||
|
||||
cat $OUTPUT_FILE
|
||||
containers:
|
||||
main:
|
||||
image:
|
||||
repository: prodrigestivill/postgres-backup-local
|
||||
tag: 16-alpine
|
||||
command: ["/backup.sh"]
|
||||
env:
|
||||
POSTGRES_DB_FILE: /config/db_list
|
||||
POSTGRES_EXTRA_OPTS: "-Z9 --schema=public --blobs"
|
||||
BACKUP_KEEP_DAYS: "7"
|
||||
BACKUP_KEEP_WEEKS: "4"
|
||||
BACKUP_KEEP_MONTHS: "3"
|
||||
HEALTHCHECK_PORT: "8080"
|
||||
envFrom: *envFrom
|
||||
service:
|
||||
main:
|
||||
enabled: false
|
||||
persistence:
|
||||
config:
|
||||
enabled: true
|
||||
type: emptyDir
|
||||
globalMounts:
|
||||
- path: /config
|
||||
backups:
|
||||
enabled: true
|
||||
type: nfs
|
||||
server: "192.168.9.10"
|
||||
path: /mnt/storage/backups/postgresql
|
||||
globalMounts:
|
||||
- path: /backups
|
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/kustomization.json
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: default
|
||||
resources:
|
||||
- ./externalsecret.yaml
|
||||
- ./helmrelease.yaml
|
Reference in New Issue
Block a user