🚀 cloudnative-pg

This commit is contained in:
auricom
2024-01-25 01:26:56 +01:00
parent 05e8b34b3a
commit bc41f2d151
14 changed files with 150 additions and 99 deletions

View File

@@ -0,0 +1,70 @@
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgres16
spec:
instances: 3
imageName: ghcr.io/bo0tzz/cnpgvecto.rs:16.1
primaryUpdateStrategy: unsupervised
storage:
size: 50Gi
storageClass: local-hostpath
superuserSecret:
name: cloudnative-pg-secret
enableSuperuserAccess: true
resources:
requests:
cpu: 500m
limits:
memory: 4Gi
postgresql:
parameters:
max_connections: "600"
max_slot_wal_keep_size: 10GB
shared_buffers: 512MB
monitoring:
enablePodMonitor: true
# Ref: https://github.com/cloudnative-pg/cloudnative-pg/issues/2501
podMonitorMetricRelabelings:
- { sourceLabels: ["cluster"], targetLabel: cnpg_cluster, action: replace }
- { regex: cluster, action: labeldrop }
backup:
retentionPolicy: 30d
barmanObjectStore:
data:
compression: bzip2
wal:
compression: bzip2
maxParallel: 8
destinationPath: s3://postgresql/
endpointURL: https://minio.${SECRET_DOMAIN}:9000
# Note: serverName version needs to be inclemented
# when recovering from an existing cnpg cluster
serverName: postgres16-v1
s3Credentials:
accessKeyId:
name: cloudnative-pg-secret
key: aws-access-key-id
secretAccessKey:
name: cloudnative-pg-secret
key: aws-secret-access-key
# # Note: previousCluster needs to be set to the name of the previous
# # cluster when recovering from an existing cnpg cluster
# bootstrap:
# recovery:
# source: postgres-v6
# externalClusters:
# - name: postgres-v6
# barmanObjectStore:
# destinationPath: s3://postgresql/
# endpointURL: https://minio.${SECRET_DOMAIN}:9000
# s3Credentials:
# accessKeyId:
# name: postgres-minio
# key: MINIO_ACCESS_KEY
# secretAccessKey:
# name: postgres-minio
# key: MINIO_SECRET_KEY
# wal:
# maxParallel: 8

View File

@@ -0,0 +1,9 @@
---
# 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:
- ./cluster16.yaml
- ./prometheusrule.yaml
- ./scheduledbackup.yaml

View File

@@ -0,0 +1,67 @@
---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/monitoring.coreos.com/prometheusrule_v1.json
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: cloudnative-pg-rules
labels:
prometheus: k8s
role: alert-rules
spec:
groups:
- name: cloudnative-pg.rules
rules:
- alert: LongRunningTransaction
annotations:
description: Pod {{ $labels.pod }} is taking more than 5 minutes (300 seconds) for a query.
summary: A query is taking longer than 5 minutes.
expr: |-
cnpg_backends_max_tx_duration_seconds > 300
for: 1m
labels:
severity: warning
- alert: BackendsWaiting
annotations:
description: Pod {{ $labels.pod }} has been waiting for longer than 5 minutes
summary: If a backend is waiting for longer than 5 minutes
expr: |-
cnpg_backends_waiting_total > 300
for: 1m
labels:
severity: warning
- alert: PGDatabase
annotations:
description: Over 150,000,000 transactions from frozen xid on pod {{ $labels.pod }}
summary: Number of transactions from the frozen XID to the current one
expr: |-
cnpg_pg_database_xid_age > 150000000
for: 1m
labels:
severity: warning
- alert: PGReplication
annotations:
description: Standby is lagging behind by over 300 seconds (5 minutes)
summary: The standby is lagging behind the primary
expr: |-
cnpg_pg_replication_lag > 300
for: 1m
labels:
severity: warning
- alert: LastFailedArchiveTime
annotations:
description: Archiving failed for {{ $labels.pod }}
summary: Checks the last time archiving failed. Will be < 0 when it has not failed.
expr: |-
(cnpg_pg_stat_archiver_last_failed_time - cnpg_pg_stat_archiver_last_archived_time) > 1
for: 1m
labels:
severity: warning
- alert: DatabaseDeadlockConflicts
annotations:
description: There are over 10 deadlock conflicts in {{ $labels.pod }}
summary: Checks the number of database conflicts
expr: |-
cnpg_pg_stat_database_deadlocks > 10
for: 1m
labels:
severity: warning

View File

@@ -0,0 +1,11 @@
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: postgres
spec:
schedule: "@daily"
immediate: true
backupOwnerReference: self
cluster:
name: postgres16