我的用例是根据应用程序洞察自定义查询结果扩展 AKS POD。但我找不到任何可以做到这一点的例子。 KEDA 文档仅建议使用内置指标 id。
以下是我想要实现的目标。但它总是说未提供指标 ID。但我想使用自定义查询而不是现有的指标 ID。
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 #Change to define how many minimum replicas you want
maxReplicaCount: 4
triggers:
- type: azure-app-insights
metadata:
query: "requests | summarize sum(itemCount) by name | where name == 'GET WeatherForecast/Get' | project sum_itemCount"
timespan: "PT10S"
targetValue: "10"
authenticationRef:
name: trigger-podIdentity-auth
有什么建议如何使用KEDA来实现吗?可以用内置的metric id来实现吗?
如果您有基于工作区的应用程序洞察资源,或者您能够转换经典资源,则可以使用Azure Log Analytics 缩放器。来自文档的示例:
triggers:
- type: azure-log-analytics
metadata:
tenantId: "AZURE_AD_TENANT_ID"
clientId: "SERVICE_PRINCIPAL_CLIENT_ID"
clientSecret: "SERVICE_PRINCIPAL_PASSWORD"
workspaceId: "LOG_ANALYTICS_WORKSPACE_ID"
query: |
let AppName = "web";
let ClusterName = "demo-cluster";
let AvgDuration = ago(10m);
let ThresholdCoefficient = 0.8;
Perf
| where InstanceName contains AppName
| where InstanceName contains ClusterName
| where CounterName == "cpuUsageNanoCores"
| where TimeGenerated > AvgDuration
| extend AppName = substring(InstanceName, indexof((InstanceName), "/", 0, -1, 10) + 1)
| summarize MetricValue=round(avg(CounterValue)) by CounterName, AppName
| join (Perf
| where InstanceName contains AppName
| where InstanceName contains ClusterName
| where CounterName == "cpuLimitNanoCores"
| where TimeGenerated > AvgDuration
| extend AppName = substring(InstanceName, indexof((InstanceName), "/", 0, -1, 10) + 1)
| summarize arg_max(TimeGenerated, *) by AppName, CounterName
| project Limit = CounterValue, TimeGenerated, CounterPath, AppName)
on AppName
| project MetricValue, Threshold = Limit * ThresholdCoefficient
threshold: "10.7"
activationThreshold: "1.7"
# Alternatively, you can use existing environment variables to read configuration from:
# See details in "Parameter list" section
workspaceIdFromEnv: LOG_ANALYTICS_WORKSPACE_ID_ENV_NAME # Optional. You can use this instead of `workspaceId` parameter.
clientIdFromEnv: SERVICE_PRINCIPAL_CLIENT_ID_ENV_NAME # Optional. You can use this instead of `clientId` parameter.
tenantIdFromEnv: AZURE_AD_TENANT_ID_ENV_NAME # Optional. You can use this instead of `tenantId` parameter.
clientSecretFromEnv: SERVICE_PRINCIPAL_PASSWORD_ENV_NAME # Optional. You can use this instead of `clientSecret` parameter.
# Optional (Default: AzurePublicCloud)
cloud: Private
# Required when cloud = Private
logAnalyticsResourceURL: https://api.loganalytics.airgap.io/
# Required when cloud = Private.
activeDirectoryEndpoint: https://login.airgap.example/
# Optional (Default: false)
unsafeSsl: "false"