# services/hermes/model-gate-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hermes-model-gate
  namespace: hermes
  labels:
    app: hermes-model-gate
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: hermes-model-gate
  template:
    metadata:
      labels:
        app: hermes-model-gate
    spec:
      serviceAccountName: hermes-model-gate
      securityContext:
        seccompProfile:
          type: RuntimeDefault
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: In
                    values:
                      - arm64
                  - key: node-role.kubernetes.io/worker
                    operator: In
                    values:
                      - "true"
                  - key: kubernetes.io/hostname
                    operator: NotIn
                    values:
                      - titan-04
                      - titan-13
                      - titan-15
                      - titan-17
                      - titan-19
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 90
              preference:
                matchExpressions:
                  - key: hardware
                    operator: In
                    values:
                      - rpi5
      containers:
        - name: model-gate
          image: python@sha256:6d43704baacd1bfbe7c295d7f13079d5d8104ed33568873133f8fc69980419df
          imagePullPolicy: IfNotPresent
          command:
            - python
            - /opt/model-gate/model_gate.py
          ports:
            - name: http
              containerPort: 8080
          env:
            - name: UPSTREAM_URL
              value: http://hermes-ollama.hermes.svc.cluster.local:11434
            - name: LEASE_NAMESPACE
              value: hermes
            - name: LEASE_NAME
              value: titan-24-gpu-owner
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 3
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 10
            periodSeconds: 30
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            runAsUser: 65532
          resources:
            requests:
              cpu: 25m
              memory: 32Mi
            limits:
              cpu: 250m
              memory: 128Mi
          volumeMounts:
            - name: script
              mountPath: /opt/model-gate
              readOnly: true
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: script
          configMap:
            name: hermes-model-gate
            defaultMode: 0555
        - name: tmp
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: hermes-model-gate
  namespace: hermes
  labels:
    app: hermes-model-gate
spec:
  type: ClusterIP
  selector:
    app: hermes-model-gate
  ports:
    - name: http
      port: 11434
      targetPort: http
