Database Layer (CloudNativePG and DragonflyDB)
Relevant source files
- kubernetes/apps/database/cloudnative-pg/app/helmrelease.yaml
- kubernetes/apps/database/cloudnative-pg/app/kustomization.yaml
- kubernetes/apps/database/cloudnative-pg/backup/externalsecret.yaml
- kubernetes/apps/database/cloudnative-pg/backup/helmrelease.yaml
- kubernetes/apps/database/cloudnative-pg/backup/kustomization.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/backup.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/externalsecret.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/kustomization.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/prometheusrule.yaml
- kubernetes/apps/database/cloudnative-pg/cluster/service.yaml
- kubernetes/apps/database/cloudnative-pg/ks.yaml
- kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml
- kubernetes/apps/database/dragonfly-operator/app/kustomization.yaml
- kubernetes/apps/database/dragonfly-operator/cluster/kustomization.yaml
- kubernetes/apps/database/dragonfly-operator/cluster/podmonitor.yaml
- kubernetes/apps/database/dragonfly-operator/ks.yaml
- kubernetes/apps/database/kustomization.yaml
- kubernetes/apps/database/mosquitto/app/helmrelease.yaml
- kubernetes/apps/database/mosquitto/app/kustomization.yaml
- kubernetes/apps/database/mosquitto/app/pvc.yaml
- kubernetes/apps/default/kustomization.yaml
- kubernetes/apps/downloads/kustomization.yaml
- kubernetes/apps/home-automation/kustomization.yaml
- kubernetes/apps/media/kustomization.yaml
- kubernetes/apps/observability/kustomization.yaml
- kubernetes/apps/security/kustomization.yaml
- kubernetes/apps/storage/kustomization.yaml
The database layer provides the stateful foundation for the home-ops cluster, primarily utilizing the CloudNativePG (CNPG) operator for PostgreSQL and the DragonflyDB operator for Redis-compatible caching. This layer is designed for high availability, automated backups, and Point-In-Time Recovery (PITR) capabilities.
CloudNativePG (PostgreSQL)
The cluster manages PostgreSQL through the CloudNativePG operator, which handles the lifecycle of the database including provisioning, master election, and replication kubernetes/apps/database/cloudnative-pg/app/helmrelease.yaml19-45
Cluster Configuration and Recovery
The primary database cluster, named postgres, is configured as a single-instance setup for resource efficiency while maintaining enterprise-grade backup features kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml4-11 It uses local-hostpath storage for high performance kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml19
A critical feature is the Point-In-Time Recovery (PITR) and migration support. The configuration includes a bootstrap section that allows the cluster to recover from a previous cluster (e.g., postgres-v11) by targeting a specific timestamp kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml35-39
Backup and WAL Archiving
Data durability is ensured through a multi-tier backup strategy:
- WAL Archiving (Garage S3): Write-Ahead Logs (WAL) are continuously archived to a Garage S3 bucket (
s3://postgresql/) usingbzip2compression kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml42-49 - Object Store Backups: Full backups are stored in the same S3 destination with a 30-day retention policy kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml40-41
- Local pg_dump Backups: A secondary
cronjob(managed viaapp-template) performs dailypg_dumpoperations for specific databases likesureandauthentikkubernetes/apps/database/cloudnative-pg/backup/helmrelease.yaml23-55 These are stored on an NFS mount at/tank/Backup/Databasekubernetes/apps/database/cloudnative-pg/backup/helmrelease.yaml61-64
Database Data Flow and Backup Topology
The following diagram illustrates the relationship between the PostgreSQL cluster, the S3 storage for WAL/PITR, and the NFS storage for logical dumps.
PostgreSQL Backup and Recovery Architecture
[Flowchart Diagram]
Sources: kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml40-65kubernetes/apps/database/cloudnative-pg/backup/helmrelease.yaml23-64
DragonflyDB (Redis-Compatible)
DragonflyDB serves as a high-performance, Redis-compatible multi-threaded data store. It is managed by the dragonfly-operatorkubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml17-20
The operator is deployed via an OCI repository kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml1-13 It includes built-in monitoring integration, deploying a Grafana dashboard into the database folder kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml36-38 DragonflyDB is primarily utilized by services like Authentik for session caching and high-speed state management.
Sources: kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml1-39kubernetes/apps/security/kustomization.yaml10
Mosquitto MQTT Broker
The mosquitto broker is deployed in the database namespace to support the Home Automation stack (e.g., Home Assistant, Frigate) kubernetes/apps/database/kustomization.yaml11 It provides the messaging backbone for IoT device communication across different VLANs kubernetes/apps/home-automation/kustomization.yaml11-12
Sources: kubernetes/apps/database/kustomization.yaml11kubernetes/apps/home-automation/kustomization.yaml11-12
Monitoring and Observability
The database layer is deeply integrated with the observability stack:
| Component | Monitoring Implementation | Source |
|---|---|---|
| PostgreSQL | podMonitorEnabled in operator and custom PodMonitor relabeling for cnpg_cluster labels. | kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml27-34 |
| DragonflyDB | grafanaDashboard enabled in operator values. | kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml36-38 |
| Alerting | PrometheusRule resources define alerts for database health. | kubernetes/apps/database/cloudnative-pg/cluster/prometheusrule.yaml |
Code Entity Mapping
This diagram bridges the natural language concepts of the database layer to the specific Kubernetes resources and files defined in the repository.
Database Layer Entity Map
[Flowchart Diagram]
Sources: kubernetes/apps/database/cloudnative-pg/cluster/cluster.yaml1-5kubernetes/apps/database/cloudnative-pg/app/helmrelease.yaml15-19kubernetes/apps/database/dragonfly-operator/app/helmrelease.yaml15-19kubernetes/apps/database/cloudnative-pg/backup/helmrelease.yaml1-5