# Title: Weather ML Application Deployment# Purpose: Defines the main FastAPI application for weather forecasting MLOps platform# Owner: MLOps Team# Source: k8s/deployment.yaml# Last-Reviewed: 2025-08-24# Depends-On: k8s/pvc.yaml, k8s/service.yaml, docker-compose.yml# Change-Log:# 2025-08-24: Updated comments and documentation structure# 2024-01-01: Initial deployment configuration# Links: https://github.com/user/weather-ml-platform# WHY: Core API configuration establishes deployment type and Kubernetes compatibilityapiVersion:apps/v1# Kubernetes API version for Deployment resourceskind:Deployment# Defines this as a Deployment resource type# WHY: Metadata uniquely identifies this deployment and enables service discoverymetadata:name:weather-ml-app# Unique name for this deployment within namespacelabels:app:weather-ml-app# Labels enable service discovery and pod selection# WHY: Spec defines deployment behavior, scaling, and pod templatespec:replicas:1# Single replica simplifies demo, enables scalingselector:# Selector identifies pods managed by this deploymentmatchLabels:app:weather-ml-app# Must match labels in pod template below for association# WHY: Template defines blueprint for pods created by this deploymenttemplate:metadata:labels:app:weather-ml-app# Labels must match selector for pod associationspec:# WHY: Init containers ensure dependencies are ready before main containers startinitContainers:-name:wait-for-postgres# Unique identifier for this init containerimage:busybox:1.36# Minimal networking tools imagecommand:['sh','-c','untilnc-zvpostgres5432;doecho"Waitingforpostgres...";sleep2;done;']# WHY: Ensures PostgreSQL availability before FastAPI starts, preventing race conditions# WHY: Main container runs the FastAPI application with all required dependenciescontainers:-name:weather-ml-container# Unique container identifier within podimage:ml-weather-app:latest# Local Docker image for developmentimagePullPolicy:Never# Use local image in development environment# WHY: Network configuration exposes FastAPI service internallyports:-containerPort:8000# Internal FastAPI listening port# WHY: Environment variables loaded from ConfigMap for configurationenvFrom:-configMapRef:name:app-config# External ConfigMap provides environment variables# WHY: Persistent volume for model artifacts and shared application datavolumeMounts:-name:data-storage# References persistent volume definitionmountPath:/data# Mount point for data accessreadOnly:false# Enable write access for model storage# WHY: Write access needed for ML models and data files# WHY: Resource allocation ensures predictable performance and prevents overconsumptionresources:# WHY: Minimum guaranteed resources for pod schedulingrequests:cpu:"250m"# 25% of CPU core minimummemory:"128Mi"# 128 MB RAM minimum# WHY: Hard limits prevent resource exhaustionlimits:cpu:"1"# 100% of CPU core maximummemory:"512Mi"# 512 MB RAM maximum# WHY: Security hardening prevents common container vulnerabilitiessecurityContext:runAsNonRoot:true# Security: run as non-root userrunAsUser:1000# Specific user ID from DockerfileallowPrivilegeEscalation:false# Security: prevent privilege escalationcapabilities:# Security: manage Linux capabilitiesdrop:["ALL"]# Security: drop all capabilities by defaultreadOnlyRootFilesystem:false# Allow writes for temporary files# WHY: Health checks enable automated monitoring and self-healingreadinessProbe:# Determines when pod can receive traffichttpGet:path:/docs# FastAPI endpoint for health verificationport:8000# Container internal portinitialDelaySeconds:15# Initial delay before first probeperiodSeconds:10# Time between probe attemptstimeoutSeconds:5# Maximum response timefailureThreshold:6# Failures before marking unreadysuccessThreshold:1# Successes to mark readylivenessProbe:# Determines when pod should restarthttpGet:path:/docs# Consistent endpoint with readinessport:8000initialDelaySeconds:30# Longer delay for startup timeperiodSeconds:20# Less frequent than readiness checkstimeoutSeconds:5failureThreshold:3# Restart after fewer failuressuccessThreshold:1# WHY: Persistent volume provides durable storage for ML models and application datavolumes:-name:data-storage# Referenced by volumeMounts abovepersistentVolumeClaim:# Use PVC for dynamic volume provisioningclaimName:data-pvc# References PVC defined in k8s/pvc.yaml