##
## vLLM Deployment — Llama 3.3 70B (Reasoning Model)
## Requires 2x NVIDIA A100 80GB GPUs with tensor parallelism.
##
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-llama
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: vllm
    model: llama-reasoning
spec:
  replicas: 2
  selector:
    matchLabels:
      app: fogbreak
      component: vllm
      model: llama-reasoning
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: fogbreak
        component: vllm
        model: llama-reasoning
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8000"
        prometheus.io/path: "/metrics"
    spec:
      terminationGracePeriodSeconds: 120
      containers:
        - name: vllm
          image: vllm/vllm-openai:latest
          args:
            - "--model"
            - "meta-llama/Llama-3.3-70B"
            - "--tensor-parallel-size"
            - "2"
            - "--max-model-len"
            - "8192"
            - "--port"
            - "8000"
            - "--gpu-memory-utilization"
            - "0.90"
            - "--max-num-seqs"
            - "64"
            - "--enable-prefix-caching"
          resources:
            requests:
              cpu: "4"
              memory: "32Gi"
              nvidia.com/gpu: 2
            limits:
              cpu: "8"
              memory: "64Gi"
              nvidia.com/gpu: 2
          ports:
            - name: http
              containerPort: 8000
              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: 120
            periodSeconds: 30
            timeoutSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          startupProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
            failureThreshold: 30
          volumeMounts:
            - name: model-cache
              mountPath: /root/.cache/huggingface
            - name: shm
              mountPath: /dev/shm
      volumes:
        - name: model-cache
          persistentVolumeClaim:
            claimName: vllm-llama-model-cache
        - name: shm
          emptyDir:
            medium: Memory
            sizeLimit: 16Gi
      nodeSelector:
        nvidia.com/gpu.product: "NVIDIA-A100-SXM4-80GB"
      tolerations:
        - key: nvidia.com/gpu
          operator: Exists
          effect: NoSchedule
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vllm-llama-model-cache
  namespace: fogbreak-ai
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Gi
  storageClassName: fast-ssd
