##
## Prometheus Deployment for Fogbreak AI monitoring.
##
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus
  namespace: fogbreak-ai
  labels:
    app: fogbreak
    component: prometheus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fogbreak
      component: prometheus
  template:
    metadata:
      labels:
        app: fogbreak
        component: prometheus
    spec:
      serviceAccountName: prometheus
      containers:
        - name: prometheus
          image: prom/prometheus:v2.51.0
          args:
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus"
            - "--storage.tsdb.retention.time=30d"
            - "--web.enable-lifecycle"
          ports:
            - name: http
              containerPort: 9090
          resources:
            requests:
              cpu: "500m"
              memory: "1Gi"
            limits:
              cpu: "1"
              memory: "2Gi"
          volumeMounts:
            - name: config
              mountPath: /etc/prometheus
            - name: storage
              mountPath: /prometheus
      volumes:
        - name: config
          configMap:
            name: prometheus-config
        - name: storage
          persistentVolumeClaim:
            claimName: prometheus-storage
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-storage
  namespace: fogbreak-ai
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus
  namespace: fogbreak-ai
spec:
  type: ClusterIP
  selector:
    app: fogbreak
    component: prometheus
  ports:
    - name: http
      port: 9090
      targetPort: 9090
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus
  namespace: fogbreak-ai
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: fogbreak-prometheus
rules:
  - apiGroups: [""]
    resources: ["pods", "services", "endpoints"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: fogbreak-prometheus
subjects:
  - kind: ServiceAccount
    name: prometheus
    namespace: fogbreak-ai
roleRef:
  kind: ClusterRole
  name: fogbreak-prometheus
  apiGroup: rbac.authorization.k8s.io
