如何基于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实现缩放:
- 先在Azure门户的Application Insights「指标」页面,找到对应业务指标的Metric ID(比如请求总数的Metric ID为
requests/count) - 替换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
相关产品推荐
相关产品推荐

