##
## vLLM Deployment — Mistral 7B Instruct (Fast Model)
## Requires 1x NVIDIA A100 40GB or L4 GPU.
##
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-mistral
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: vllm
    model: mistral-fast
spec:
  replicas: 2
  selector:
    matchLabels:
      app: fogbreak
      component: vllm
      model: mistral-fast
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: fogbreak
        component: vllm
        model: mistral-fast
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8001"
        prometheus.io/path: "/metrics"
    spec:
      terminationGracePeriodSeconds: 60
      containers:
        - name: vllm
          image: vllm/vllm-openai:latest
          args:
            - "--model"
            - "mistralai/Mistral-7B-Instruct-v0.3"
            - "--max-model-len"
            - "8192"
            - "--port"
            - "8001"
            - "--gpu-memory-utilization"
            - "0.90"
            - "--max-num-seqs"
            - "128"
            - "--enable-prefix-caching"
          resources:
            requests:
              cpu: "2"
              memory: "16Gi"
              nvidia.com/gpu: 1
            limits:
              cpu: "4"
              memory: "32Gi"
              nvidia.com/gpu: 1
          ports:
            - name: http
              containerPort: 8001
              protocol: TCP
          env:
            - name: HF_TOKEN
              valueFrom:
                secretKeyRef:
                  name: fogbreak-ai-secrets
                  key: hf-token
            - name: VLLM_LOGGING_LEVEL
              value: "INFO"
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          startupProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 15
            periodSeconds: 10
            failureThreshold: 20
          volumeMounts:
            - name: model-cache
              mountPath: /root/.cache/huggingface
            - name: shm
              mountPath: /dev/shm
      volumes:
        - name: model-cache
          persistentVolumeClaim:
            claimName: vllm-mistral-model-cache
        - name: shm
          emptyDir:
            medium: Memory
            sizeLimit: 4Gi
      tolerations:
        - key: nvidia.com/gpu
          operator: Exists
          effect: NoSchedule
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vllm-mistral-model-cache
  namespace: fogbreak-ai
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
  storageClassName: fast-ssd
