##
## Kubernetes Services for vLLM model endpoints.
##
apiVersion: v1
kind: Service
metadata:
  name: vllm-llama
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: vllm
    model: llama-reasoning
spec:
  type: ClusterIP
  selector:
    app: fogbreak
    component: vllm
    model: llama-reasoning
  ports:
    - name: http
      port: 8000
      targetPort: 8000
      protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: vllm-mistral
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: vllm
    model: mistral-fast
spec:
  type: ClusterIP
  selector:
    app: fogbreak
    component: vllm
    model: mistral-fast
  ports:
    - name: http
      port: 8001
      targetPort: 8001
      protocol: TCP
---
##
## FastAPI Proxy Deployment + Service
##
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fogbreak-ai-proxy
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: ai-proxy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: fogbreak
      component: ai-proxy
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: fogbreak
        component: ai-proxy
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
        prometheus.io/path: "/metrics"
    spec:
      containers:
        - name: proxy
          image: fogbreak/ai-proxy:latest
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          env:
            - name: FOGBREAK_AI_API_KEY
              valueFrom:
                secretKeyRef:
                  name: fogbreak-ai-secrets
                  key: api-key
            - name: VLLM_REASONING_URL
              value: "http://vllm-llama:8000"
            - name: VLLM_REASONING_MODEL
              value: "meta-llama/Llama-3.3-70B"
            - name: VLLM_FAST_URL
              value: "http://vllm-mistral:8001"
            - name: VLLM_FAST_MODEL
              value: "mistralai/Mistral-7B-Instruct-v0.3"
            - name: FOGBREAK_CORS_ORIGINS
              value: "https://fogbreak.io,https://*.fogbreak.io"
          resources:
            requests:
              cpu: "500m"
              memory: "512Mi"
            limits:
              cpu: "2"
              memory: "1Gi"
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 10
            periodSeconds: 15
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: fogbreak-ai-proxy
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: ai-proxy
spec:
  type: ClusterIP
  selector:
    app: fogbreak
    component: ai-proxy
  ports:
    - name: http
      port: 8080
      targetPort: 8080
      protocol: TCP
---
##
## Ingress — External access to AI proxy
##
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: fogbreak-ai-ingress
  namespace: fogbreak-ai
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rate-limit: "100"
    nginx.ingress.kubernetes.io/rate-limit-window: "1m"
    nginx.ingress.kubernetes.io/proxy-body-size: "10m"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "120"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - ai.fogbreak.io
      secretName: fogbreak-ai-tls
  rules:
    - host: ai.fogbreak.io
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: fogbreak-ai-proxy
                port:
                  number: 8080
