# Title: Kubernetes Service Manifest for Weather MLOps Application# Purpose: Exposes the weather forecasting FastAPI backend within the K8s cluster# Owner: Platform Team / MLOps Engineer# Source: k8s/service.yaml# Last-Reviewed: 2025-08-24# Depends-On: k8s/deployment.yaml (app: weather-ml-app labels must match)# Change-Log: Added comprehensive header comments for portfolio documentation# Links: https://kubernetes.io/docs/concepts/services-networking/service/# Architecture Overview:# This Service provides stable DNS-based service discovery and automatic load balancing# for the weather forecasting FastAPI backend. Essential component of the MLOps pipeline.# Design Rationale:# WHY: ClusterIP enables secure internal-only access by default, implementing security# by design. This microservices pattern allows seamless pod communication while# maintaining isolation. External access is managed by separate Ingress resources for# better control and security layering.# Core Design Decisions:# - ClusterIP type: Zero-trust security model with explicit external access# - Port mapping (80→8000): Standard HTTP ports with clear service/target separation# - Label selectors: Exact match with deployment.yaml ensures proper pod targeting# - No session affinity: Enables true load balancing across all healthy pods# API Resource Declaration# WHY: apiVersion v1 is the stable core API for basic Kubernetes resourcesapiVersion:v1kind:Service# Service Identity and Classification# WHY: Metadata enables resource discovery, organization, and proper lifecycle managementmetadata:# Service identity within the namespace - used by other resources for discoveryname:weather-ml-service# Resource classification for management and selection by other Kubernetes objectslabels:# Primary app label - CRITICAL: must match Deployment labels for proper operationapp:weather-ml-app# Service Behavior Specification# WHY: Spec defines the operational parameters and routing behavior of the Servicespec:# Pod Selection Logic# WHY: Label-based selection enables dynamic pod discovery and load balancing# CRITICAL: Selector labels MUST exactly match the pod template labels in deployment.yamlselector:app:weather-ml-app# Network Endpoint Configuration# WHY: Defines the traffic routing from Service endpoints to container portsports:-# Network transport protocol for HTTP-based communicationprotocol:TCP# Service endpoint port - cluster-internal access point for clients# WHY: Port 80 is the standard HTTP port, expected by Ingress and other clientsport:80# Container target port where the FastAPI application listens# WHY: Must exactly match containerPort in deployment.yaml pod spec# CRITICAL: Misalignment causes connection failures and service disruptiontargetPort:8000# Service Exposure Type# WHY: Determines the security boundary and access pattern for the Service# Design Choice: ClusterIP prioritizes security over convenience for internal services# Alternatives:# - LoadBalancer: Use for production external access via cloud provider# - NodePort: Use for development/testing with direct node accesstype:ClusterIP