You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于Application Insights自定义查询实现KEDA缩放AKS Pod?

基于Application Insights实现KEDA对AKS Pod的弹性缩放

一、使用自定义查询的正确配置

你的配置报错是因为未启用自定义查询模式,KEDA的Azure Application Insights触发器默认要求提供metricId,若要使用自定义Log Analytics查询,必须添加useCustomQuery: "true"元数据参数。修改后的完整配置如下:

apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: trigger-podidentity-auth
spec:
  podIdentity:
    provider: azure-workload
    identityId: 6d12e654-770d-4607-8a31-0ade5472e803
---
apiVersion: keda.sh/v1alpha1 
kind: ScaledObject
metadata:
  name: webapp-demo-scaleobject
  namespace: demo-cluster-ns
spec:
  scaleTargetRef:
    name: webapp-demo
  minReplicaCount: 1
  maxReplicaCount: 4
  triggers:
  - type: azure-app-insights
    metadata:
      useCustomQuery: "true"  # 启用自定义查询模式
      query: "requests | summarize sum(itemCount) by name | where name == 'GET WeatherForecast/Get' | project sum_itemCount"
      timespan: "PT10S"
      targetValue: "10"
      # 指定Application Insights实例的资源ID,KEDA需通过此定位目标资源
      resourceURI: "/subscriptions/{你的订阅ID}/resourceGroups/{资源组}/providers/microsoft.insights/components/{AI实例名称}"
    authenticationRef:
      name: trigger-podidentity-auth

关键注意点:

  • 自定义查询必须返回单个数值,KEDA会基于该数值与targetValue计算所需副本数
  • 必须补充resourceURI参数,明确指定目标Application Insights实例的资源标识

二、使用内置Metric ID的实现方式

如果不想编写自定义查询,也可以通过KEDA内置的Application Insights Metric ID实现缩放:

  1. 先在Azure门户的Application Insights「指标」页面,找到对应业务指标的Metric ID(比如请求总数的Metric ID为requests/count)
  2. 替换ScaledObject的触发器配置为内置Metric参数:
triggers:
- type: azure-app-insights
  metadata:
    metricId: "requests/count"
    aggregation: "Sum"  # 选择匹配需求的聚合方式,如Sum、Average等
    filter: "name eq 'GET WeatherForecast/Get'"  # 对应自定义查询中的过滤逻辑
    timespan: "PT10S"
    targetValue: "10"
    resourceURI: "/subscriptions/{你的订阅ID}/resourceGroups/{资源组}/providers/microsoft.insights/components/{AI实例名称}"
  authenticationRef:
    name: trigger-podidentity-auth

这种方式无需编写自定义查询,直接利用KEDA预定义的Metric ID,适合标准指标的缩放场景。

内容的提问来源于stack exchange,提问作者Chandra Mohan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 15:52:13