Azure Kubernetes 服务 (AKS)的 GPU 分析常见问题(预览版)

查找有关在 Azure Kubernetes 服务 (AKS) 上进行 GPU 性能分析时的监控集成和分析数据存储的常见问题解答。 在开始之前,设置 GPU 性能分析。

监控集成

如何将自己的 Prometheus 实例接入 Inspektor Gadget?

如果你运行的是自己的 Prometheus 实例,而不是 Azure Monitor 的 Prometheus 托管服务,请将其配置为从 Inspektor Gadget Pod 中抓取指标。

Inspektor Gadget 在以下端点公开其指标:

设置 价值
命名空间 gadget
港口 2224
路径 /metrics

将一个抓取作业添加到 Prometheus 配置中,以发现并抓取这些 Pod:

Tip

对于 Prometheus Operator 部署,请创建一个具有对应命名空间、标签选择器、端口和指标路径的 PodMonitor。

scrape_configs:
  - job_name: "inspektor-gadget"
    kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
            - gadget
    relabel_configs:
      # Only keep pods with the k8s-app=gadget label.
      - source_labels: [__meta_kubernetes_pod_label_k8s_app]
        action: keep
        regex: gadget

      # Set the metrics path.
      - target_label: __metrics_path__
        replacement: /metrics

      # Set the metrics port.
      - source_labels: [__address__]
        action: replace
        regex: ([^:]+)(?::\d+)?
        replacement: $1:2224
        target_label: __address__

在 Prometheus UI 的状态>下检查连接。 inspektor-gadget任务的目标应显示为UP。

如何在我自己的 Grafana 实例中将 Inspektor Gadget 指标可视化?

确保已将 Prometheus 实例作为数据源连接到 Grafana。 然后,从以下 JSON 定义导入 Inspektor 小工具仪表板:

https://raw.githubusercontent.com/inspektor-gadget/grafana-dashboards/refs/heads/main/dashboards/gpu-observability/AdvancedGPUObservability.json

档案存储

如何将Azure Blob 存储用作火镜后端?

默认情况下, GPU 分析设置文章 中的 Pyroscope 部署将配置文件存储在本地文件系统上。 如果 Pod 被重新创建,性能分析数据将会丢失。 若要持久化剖析数据,请将 Pyroscope 配置为使用带有 Microsoft Entra Workload ID 的 Azure Blob 存储。

导出所需的变量:

export RESOURCE_GROUP="<your-resource-group>"
export AKS_CLUSTER="<your-aks-cluster-name>"
export LOCATION="<your-aks-cluster-location>"
export BLOB_STORAGE_NAME="<your-storage-account-name>"

export BLOB_STORAGE_CONTAINER="pyroscope-blob-storage"
export PYROSCOPE_IDENTITY="pyroscope-id"
export PYROSCOPE_SERVICE_ACCOUNT="pyroscope-sa"
export PYROSCOPE_FEDERATED_CREDS="pyroscope-federated-creds"

创建存储帐户和容器

az storage account create \
  --name "$BLOB_STORAGE_NAME" \
  --resource-group "$RESOURCE_GROUP" \
  --location "$LOCATION" \
  --sku Standard_ZRS \
  --kind StorageV2 \
  --min-tls-version TLS1_2 \
  --allow-blob-public-access false \
  --output none

az storage container create \
  --name "$BLOB_STORAGE_CONTAINER" \
  --account-name "$BLOB_STORAGE_NAME" \
  --auth-mode login \
  --output none

创建托管标识并授予对存储帐户的访问权限

az identity create \
  --name "$PYROSCOPE_IDENTITY" \
  --resource-group "$RESOURCE_GROUP" \
  --location "$LOCATION" \
  --output none

IDENTITY_CLIENT_ID=$(az identity show \
  --name "$PYROSCOPE_IDENTITY" \
  --resource-group "$RESOURCE_GROUP" \
  --query 'clientId' \
  --output tsv)

SUBSCRIPTION_ID=$(az account show --query id --output tsv)

# Restrict the role assignment scope to the storage account.
STORAGE_SCOPE="/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Storage/storageAccounts/${BLOB_STORAGE_NAME}"

az role assignment create \
  --assignee "$IDENTITY_CLIENT_ID" \
  --role "Storage Blob Data Contributor" \
  --scope "$STORAGE_SCOPE" \
  --output none

启用工作负载标识并创建联合凭据

az aks update \
  --name "$AKS_CLUSTER" \
  --resource-group "$RESOURCE_GROUP" \
  --enable-oidc-issuer \
  --enable-workload-identity \
  --output none

OIDC_ISSUER=$(az aks show \
  --name "$AKS_CLUSTER" \
  --resource-group "$RESOURCE_GROUP" \
  --query 'oidcIssuerProfile.issuerUrl' \
  --output tsv)

az identity federated-credential create \
  --name "$PYROSCOPE_FEDERATED_CREDS" \
  --identity-name "$PYROSCOPE_IDENTITY" \
  --resource-group "$RESOURCE_GROUP" \
  --issuer "$OIDC_ISSUER" \
  --subject "system:serviceaccount:gadget:${PYROSCOPE_SERVICE_ACCOUNT}" \
  --audiences "api://AzureADTokenExchange" \
  --output none

Important

联合凭据主题中的服务帐户名称必须与 Pyroscope Helm 发布中使用的服务帐户名称匹配。 否则,火镜无法向Azure Blob 存储进行身份验证。

使用 Azure Blob 存储 后端部署Pyoscope

请运行以下命令,而不要使用 使用 Pyroscope 启用性能分析可视化中的 Helm 命令。 此配置使用 Azure Blob 存储,创建服务帐户,并在Pyoscope Pod 上启用工作负荷标识。

helm install pyroscope -n gadget \
  oci://ghcr.io/grafana/helm-charts/pyroscope \
  --version 1.15.0 \
  --set pyroscope.image.repository=grafana/pyroscope \
  --set-string pyroscope.image.tag=1.15.0 \
  --set pyroscope.replicaCount=1 \
  --set pyroscope.structuredConfig.self_profiling.disable_push=true \
  --set pyroscope.structuredConfig.storage.backend=azure \
  --set-string pyroscope.structuredConfig.storage.azure.account_name="$BLOB_STORAGE_NAME" \
  --set-string pyroscope.structuredConfig.storage.azure.container_name="$BLOB_STORAGE_CONTAINER" \
  --set pyroscope.serviceAccount.create=true \
  --set-string pyroscope.serviceAccount.name="$PYROSCOPE_SERVICE_ACCOUNT" \
  --set-string pyroscope.serviceAccount.annotations."azure\.workload\.identity/client-id"="$IDENTITY_CLIENT_ID" \
  --set-string pyroscope.podLabels."azure\.workload\.identity/use"=true \
  --set pyroscope.service.type=LoadBalancer \
  --set pyroscope.service.port=4040 \
  --set-string pyroscope.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-internal"=true \
  --set-string pyroscope.service.annotations."service\.beta\.kubernetes\.io/azure-pls-create"=true \
  --set-string pyroscope.service.annotations."service\.beta\.kubernetes\.io/azure-pls-name"=pyroscope-pls \
  --set-string pyroscope.service.annotations."service\.beta\.kubernetes\.io/azure-pls-proxy-protocol"=false \
  --set-string pyroscope.service.annotations."service\.beta\.kubernetes\.io/azure-pls-visibility"='*' \
  --set alloy.enabled=false \
  --set minio.enabled=false

验证 Pod 是否正在运行:

kubectl get pods -n gadget pyroscope-0

继续进行将 Pyroscope 连接到 Azure 托管 Grafana。

注释

Helm 值键可以在图表版本之间更改。 若要确认版本的可用密钥,请运行 helm show values oci://ghcr.io/grafana/helm-charts/pyroscope --version 1.15.0。