# -----------------------------------------------------------------------------# Title: PostgreSQL Database Deployment Manifests# Purpose: Defines Kubernetes resources for PostgreSQL database in MLOps platform# Owner: MLOps Weather Forecasting Team# Source: k8s/postgres-deployment.yaml# Last-Reviewed: 2025-08-24# Depends-On: postgres-secrets (external Secret), storage-class (default)# Change-Log:# 2024-01-15: Initial creation for demo environment# 2025-08-24: Updated comments and documentation structure# Links:# - https://kubernetes.io/docs/concepts/workloads/controllers/deployment/# - https://www.postgresql.org/docs/15/index.html# -----------------------------------------------------------------------------# PostgreSQL database deployment for MLOps weather forecasting platform.## WHY: PostgreSQL serves as the central data store for weather observations,# ML training status, coordinates, and training logs. Ensures data persistence# and reliability for the distributed system architecture.## Architecture Context: Single source of truth for all weather data and ML# training state. Critical for maintaining data consistency across FastAPI# backend and Slurm training pipeline components.## Resources defined:# - PersistentVolumeClaim: Ensures data persistence across pod lifecycle# - Deployment: Runs PostgreSQL 15 with proper configuration and secret injection# - Service: Provides internal cluster networking for database connections## Security Note: Database credentials are externalized via 'postgres-secrets'# to prevent credential leakage in version control systems.---# SECTION: Data Persistence Layer# WHY: Database state must survive pod restarts and rescheduling for data integrity.# Ensures weather data, ML training status, and coordinates persist across deployments.apiVersion:v1kind:PersistentVolumeClaimmetadata:name:postgres-pvc# Referenced by postgres-storage volume in deploymentspec:accessModes:-ReadWriteOnce# Single pod access for data consistency and safetyresources:requests:storage:1Gi# Sufficient for development/demo workloads (scale up for production)---# SECTION: Database Service Deployment# WHY: Runs PostgreSQL 15 with optimized configuration for weather data storage.# Ensures consistent data handling for time-series weather observations and ML state.apiVersion:apps/v1kind:Deploymentmetadata:name:postgres# Deployment manages pod lifecycle and updates for the database servicespec:selector:matchLabels:app:postgres# Selector must match template labels for pod targetingreplicas:1# Single replica for development/demo - scale up for productiontemplate:metadata:labels:app:postgres# Service selector targetspec:containers:-name:postgresimage:postgres:15# PostgreSQL 15 for reliable performanceports:-containerPort:5432# Default PostgreSQL portenvFrom:-secretRef:name:postgres-secrets# External secret containing DB credentialsvolumeMounts:-name:postgres-storagemountPath:/var/lib/postgresql/data# PostgreSQL data directoryvolumes:-name:postgres-storagepersistentVolumeClaim:claimName:postgres-pvc# References the PVC defined above---# SECTION: Database Service Networking# WHY: Provides stable network endpoint for database connectivity within cluster.# Enables consistent service discovery for FastAPI backend and other components.apiVersion:v1kind:Servicemetadata:name:postgres# Service name becomes DNS resolvable within the cluster namespacespec:type:ClusterIP# Internal-only access - suitable for demo/developmentselector:app:postgres# Routes traffic to pods with matching labelsports:-port:5432# Service port (accessible within cluster)targetPort:5432# Maps to container port defined in deploymentprotocol:TCP# Explicit TCP protocol for clarity