본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Azure Data Explorer 스케일러

원문 보기 위키 갱신

Azure Data Explorer(ADX) 쿼리 결과를 기준으로 워크로드를 자동으로 스케일링하고 싶을 때 azure-data-explorer 트리거를 사용해요. 오늘은 이 트리거의 파라미터와 인증 방식, 다양한 예시를 함께 살펴볼게요.

출처: 문서

본문

트리거 사양 (Trigger Specification)

이 사양은 Azure Data Explorer 쿼리 결과를 기반으로 스케일링하는 azure-data-explorer 트리거를 설명해요.

triggers:
- type: azure-data-explorer
  metadata:
    endpoint: https://keda.eastus.kusto.windows.net
    databaseName: kedadb
    query: |
      StormEvents
      | summarize StormCount = count() by State
      | top 1 by StormCount desc
    threshold: "10.5"
    activationThreshold: "10.5"
    tenantId: 045ef409-6dee-4893-a824-5612eac467b1 # Can use TriggerAuthentication as well
    clientId: 4ba039f1-d69c-434e-9268-4a2bb7bba90d # Can use TriggerAuthentication as well
    # Alternatively, you can use existing environment variables to read aad app creds from:
    clientIdFromEnv: AAD_APP_CLIENT_ID_ENV_VAR_NAME # Optional. You can use this instead of `clientId` parameter.
    clientSecretFromEnv: AAD_APP_SECRET_ENV_VAR_NAME # Optional. You can use this instead of `clientSecret` parameter.
    tenantIdFromEnv: AAD_APP_TENANT_ID_ENV_VAR_NAME # Optional. You can use this instead of `tenantId` parameter.
    # Optional (Default: AzurePublicCloud)
    cloud: Private
    # Required when cloud = Private.
    activeDirectoryEndpoint: https://login.airgap.example/

파라미터 목록이에요:

  • endpoint - Data Explorer 클러스터를 쿼리할 엔드포인트예요.
  • databaseName - 쿼리할 Data Explorer 데이터베이스의 이름이에요.
  • query - Data Explorer 쿼리예요.
  • threshold - 스케일 대상의 pod 수를 계산하는 임계값으로 사용하는 값이에요. (이 값은 float일 수 있어요)
  • activationThreshold - 스케일러를 활성화하기 위한 목표 값이에요. activation에 대한 자세한 내용은 여기서 확인할 수 있어요. (기본값: 0, 선택 사항, 이 값은 float일 수 있어요)
  • tenantId - Azure AD 테넌트의 ID예요.
  • clientId - Azure AD 애플리케이션의 ID예요.
  • cloud - Azure Data Explorer 클러스터가 속한 클라우드 환경의 이름이에요. (값: AzurePublicCloud, AzureUSGovernmentCloud, AzureChinaCloud, Private, 기본값: AzurePublicCloud, 선택 사항)
  • activeDirectoryEndpoint - 클라우드 환경의 Active Directory 엔드포인트예요. (cloud가 Private으로 설정되었을 때 필수, 예를 들어 AzureChinaCloud는 https://login.chinacloudapi.cn/)

인증 파라미터는 metadata에 직접 설정하는 대신 환경 변수로도 제공할 수 있어요. 환경 변수에서 값을 가져오는 데 사용하는 파라미터 목록이에요:

  • tenantIdFromEnv - Azure AD 테넌트 ID를 저장하는 환경 변수 이름이에요. (선택 사항)
  • clientIdFromEnv - Azure AD 애플리케이션의 애플리케이션 ID를 저장하는 환경 변수 이름이에요. (선택 사항)
  • clientSecretFromEnv - Azure AD 애플리케이션의 비밀번호를 저장하는 환경 변수 이름이에요. (선택 사항)

쿼리 안내 (Query Guidance)

쿼리가 1행을 반환하도록 설계하는 것이 중요해요. 쿼리 끝에 | limit 1을 추가하는 것이 좋은 습관이에요.

쿼리 결과에 대해 지원되는 데이터 유형은 real, int, long뿐이에요.

pollingInterval을 정의할 때는 오래 실행되는 쿼리를 사용하는 데 주의해야 해요. 쿼리를 사용하기 전에 반드시 테스트해 보세요.

인증 파라미터 (Authentication Parameters)

TriggerAuthentication CRD를 사용해서 Azure Active Directory 자격 증명 세트를 제공하거나 pod identity를 사용해 인증을 구성할 수 있어요.

사용되는 AD identity는 Data Explorer 클러스터에서 메트릭을 쿼리하려면 DatabaseViewer 역할이 필요해요.

💡 이 가이드를 사용해서 Azure CLI로 사용자(principal)에 올바른 액세스 권한을 부여할 수 있어요.

자격 증명 기반 인증 (Credential based authentication):

  • clientId - Azure AD 애플리케이션의 ID예요. 이 가이드를 사용해서 service principal을 만들어요.
  • clientSecret - Azure AD 애플리케이션의 비밀번호예요.
  • tenantId - Azure AD 테넌트의 ID예요. 이 가이드를 사용해서 테넌트 ID를 가져와요.

Pod identity 기반 인증 (Pod identity based authentication):

Azure AD Workload Identity 제공자를 사용할 수 있어요.

예시 (Examples)

Azure AD 애플리케이션과 함께 TriggerAuthentication 사용 (Use TriggerAuthentication with Azure AD Application)

apiVersion: v1
kind: Secret
metadata:
  name: azure-data-explorer-secret
data:
  clientId: <clientId> # Base64 encoded
  clientSecret: <clientSecret> # Base64 encoded
  tenantId: <tenantId> # Base64 encoded
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-data-explorer-trigger-auth
spec:
  secretTargetRef:
    - parameter: clientId
      name: azure-data-explorer-secret # Required. Refers to the name of the secret
      key: clientId
    - parameter: clientSecret
      name: azure-data-explorer-secret
      key: clientSecret
    - parameter: tenantId
      name: azure-data-explorer-secret
      key: tenantId
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: azure-data-explorer-scaler
spec:
  scaleTargetRef:
  kind: StatefulSet # Optional: Default: Deployment, Available Options: ReplicaSet Deployment, DaemonSet, StatefulSet
    name: azure-data-explorer-example
  pollingInterval: 30
  cooldownPeriod: 45
  minReplicaCount: 0
  maxReplicaCount: 10
  triggers:
  - type: azure-data-explorer
    metadata:
      databaseName: Weather
      endpoint: https://keda.eastus.kusto.windows.net
      query: |
        StormEvents
        | summarize StormCount = count() by State
        | top 1 by StormCount desc
    threshold: "1000"
    authenticationRef:
      name: azure-data-explorer-trigger-auth

Azure Pod Identity와 함께 TriggerAuthentication 사용 (Use TriggerAuthentication with Azure Pod Identity)

apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: azure-data-explorer-trigger-auth
spec:
  podIdentity:
      provider: azure-workload
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: azure-data-explorer-scaler
spec:
  scaleTargetRef:
  kind: StatefulSet # Optional: Default: Deployment, Available Options: ReplicaSet Deployment, DaemonSet, StatefulSet
    name: azure-data-explorer-example
  pollingInterval: 30
  cooldownPeriod: 45
  minReplicaCount: 0
  maxReplicaCount: 10
  triggers:
  - type: azure-data-explorer
    metadata:
      databaseName: Weather
      endpoint: https://keda.eastus.kusto.windows.net
      query: |
        StormEvents
        | summarize StormCount = count() by State
        | top 1 by StormCount desc
    threshold: "1000"
    authenticationRef:
      name: azure-data-explorer-trigger-auth

환경 변수를 통해 Azure AD 애플리케이션과 함께 TriggerAuthentication 사용 (Use TriggerAuthentication with Azure AD Application through environment variables)

apiVersion: v1
kind: Secret
metadata:
  name: azure-data-explorer-secrets
type: Opaque
data:
  clientId: <clientId> # Base64 encoded
  clientSecret: <clientSecret> # Base64 encoded
  tenantId: <tenantId> # Base64 encoded
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-data-explorer-example
spec:
  replicas: 0
  selector:
    matchLabels:
      app: azure-data-explorer-example
  template:
    metadata:
      labels:
        app: azure-data-explorer-example
    spec:
      containers:
      - name: example
        image: nginx:1.16.1
        env:
        - name: AAD_APP_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: azure-data-explorer-secret
              key: clientId
        - name: AAD_APP_SECRET
          valueFrom:
            secretKeyRef:
              name: azure-data-explorer-secret
              key: clientSecret
        - name: AAD_APP_TENANT_ID
          valueFrom:
            secretKeyRef:
              name: azure-data-explorer-secret
              key: tenantId
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: azure-data-explorer-scaler
spec:
  scaleTargetRef:
    name: azure-data-explorer-example
  pollingInterval: 30
  cooldownPeriod: 45
  minReplicaCount: 0
  maxReplicaCount: 10
  triggers:
    - type: azure-data-explorer
      metadata:
        clientIdFromEnv: AAD_APP_CLIENT_ID
        clientSecretFromEnv: AAD_APP_SECRET
        tenantIdFromEnv: AAD_APP_TENANT_ID
        databaseName: Weather
        endpoint: https://keda.eastus.kusto.windows.net
        query: |
          StormEvents
          | summarize StormCount = count() by State
          | top 1 by StormCount desc
        threshold: "1000"

더 알아보기 (Learn more)

이렇게 하면 Azure Data Explorer 쿼리 결과가 임계값을 넘으면 레플리카를 늘리고, 내려가면 줄이는 자동 스케일링을 구성할 수 있어요. 쿼리가 1행의 숫자 값을 반환하도록 설계하고, DatabaseViewer 역할과 인증 설정을 잘 맞춰 두는 게 핵심이에요.