apiVersion: apps/v1
kind: Deployment
metadata:
  name: bernard-worker
  namespace: ai-agents-bernard
  labels:
    app.kubernetes.io/name: bernard-worker
    agentic-os.io/agent: bernard
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: bernard-worker
  template:
    metadata:
      labels:
        app.kubernetes.io/name: bernard-worker
        agentic-os.io/agent: bernard
    spec:
      initContainers:
        - name: git-clone
          image: alpine/git:latest
          command:
            - sh
            - -c
            - |
              git clone http://192.168.8.248:3000/deepkoluguri/agentic-os.git /workspace
          volumeMounts:
            - name: workspace
              mountPath: /workspace
      containers:
        - name: bernard-worker
          image: python:3.11-slim
          command:
            - sh
            - -c
            - |
              cd /workspace/agents/bernard && pip install -e . -q && bernard-worker
          volumeMounts:
            - name: workspace
              mountPath: /workspace
          env:
            - name: TEMPORAL_ADDRESS
              value: "temporal-frontend.ai-core.svc.cluster.local:7233"
            - name: TEMPORAL_NAMESPACE
              value: "default"
            - name: PYTHONUNBUFFERED
              value: "1"
            - name: BERNARD_TASK_QUEUE
              value: "bernard"
            - name: GITEA_BASE_URL
              value: "http://gitea.gitea.svc.cluster.local:3000"
            - name: GITEA_TOKEN
              valueFrom:
                secretKeyRef:
                  name: bernard-secrets
                  key: GITEA_TOKEN
            - name: LITELLM_API_KEY
              valueFrom:
                secretKeyRef:
                  name: bernard-litellm-key
                  key: LITELLM_API_KEY
            - name: LITELLM_BASE_URL
              value: "http://litellm.ai-core.svc.cluster.local:4000"
            - name: BERNARD_DB_DSN
              valueFrom:
                secretKeyRef:
                  name: bernard-secrets
                  key: BERNARD_DB_DSN
            - name: BERNARD_MODEL
              value: "ollama-qwen"
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
      volumes:
        - name: workspace
          emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bernard-dashboard
  namespace: ai-agents-bernard
  labels:
    app.kubernetes.io/name: bernard-dashboard
    agentic-os.io/agent: bernard
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: bernard-dashboard
  template:
    metadata:
      labels:
        app.kubernetes.io/name: bernard-dashboard
        agentic-os.io/agent: bernard
    spec:
      initContainers:
        - name: git-clone
          image: alpine/git:latest
          command:
            - sh
            - -c
            - |
              git clone http://192.168.8.248:3000/deepkoluguri/agentic-os.git /workspace
          volumeMounts:
            - name: workspace
              mountPath: /workspace
      containers:
        - name: bernard-dashboard
          image: python:3.11-slim
          command:
            - sh
            - -c
            - |
              cd /workspace/agents/bernard && pip install -e . -q && bernard-dashboard
          volumeMounts:
            - name: workspace
              mountPath: /workspace
          env:
            - name: PORT
              value: "8080"
            - name: PYTHONUNBUFFERED
              value: "1"
            - name: BERNARD_DB_DSN
              valueFrom:
                secretKeyRef:
                  name: bernard-secrets
                  key: BERNARD_DB_DSN
          ports:
            - containerPort: 8080
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 120
            periodSeconds: 15
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 120
            periodSeconds: 5
          resources:
            requests:
              cpu: 50m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
      volumes:
        - name: workspace
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: bernard-dashboard
  namespace: ai-agents-bernard
spec:
  selector:
    app.kubernetes.io/name: bernard-dashboard
  ports:
    - port: 8080
      targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: bernard-ingress
  namespace: ai-agents-bernard
spec:
  ingressClassName: apisix
  rules:
    - host: bernard.applaude.net
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: bernard-dashboard
                port:
                  number: 8080
