apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: file-storage-hpa
  namespace: default
  annotations:
    metric-config.object.istio-requests-total.prometheus/per-replica: "true"
    metric-config.object.istio-requests-total.prometheus/query: |
      sum(
          rate(
              istio_requests_total{
                destination_workload="file-storage",
                destination_workload_namespace="default",
                reporter="destination"
              }[1m]
          )
      ) /
      count(
        count(
          container_memory_usage_bytes{
            namespace="default",
          pod=~"file-storage.*"
          }
        ) by (pod)
      )
spec:
  minReplicas: 2
  maxReplicas: 5
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: file-storage
  metrics:
    - type: Object
      object:
        metricName: istio-requests-total
        target:
          apiVersion: v1
          kind: Pod
          name: file-storage
        targetValue: 10


