apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: footfall-model-pvc
  namespace: contoso-hypermarket
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: footfall-ai-api
  namespace: contoso-hypermarket
spec:
  replicas: 1
  selector:
    matchLabels:
      app: footfall-ai-api
  template:
    metadata:
      labels:
        app: footfall-ai-api
    spec:
      initContainers:
      - name: init-download-model
        image: mcr.microsoft.com/cbl-mariner/base/core:2.0   
        command:
          - sh
          - -c
          - |
            tdnf update -y
            tdnf install wget -y
            wget -O /tmp/models/yolov8n.pt download.microsoft.com/download/ad457769-60e2-4e4b-8756-8d9fada0b60a/yolov8n.pt
        volumeMounts:
        - name: models-volume
          mountPath: /tmp/models
      containers:
      - name: footfall-ai-api
        image: mcr.microsoft.com/jumpstart/agora/footfall_ai_api:1.0.0
        ports:
        - containerPort: 5000
        env:
        - name: MODEL_PATH
          value: "/tmp/models/yolov8n.pt"
        - name: RTSP_URL
          value: "rtsp://rtsp-stream-aisle:8554/stream"
        volumeMounts:
        - mountPath: /tmp/models
          name: models-volume
      volumes:
      - name: models-volume
        persistentVolumeClaim:
          claimName: footfall-model-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: footfall-ai-api
  namespace: contoso-hypermarket
spec:
  selector:
    app: footfall-ai-api
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 5000
  type: LoadBalancer
