取得有關 Azure Kubernetes Service (AKS) 上 GPU 剖析的監視整合與設定檔儲存的常見問題解答。 在開始之前,先 設定 GPU 效能分析。
監控整合
我要如何將我自己的普羅米修斯實例連接到Inspektor Gadget?
如果您執行的是自己的 Prometheus 執行個體,而不是使用適用於 Prometheus 的 Azure 監視器受管理服務,請將其設定為從 Inspektor Gadget Pod 擷取計量。
Inspektor Gadget 在以下端點揭露其指標:
| Setting | 價值 |
|---|---|
| 命名空間 | gadget |
| Port | 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 Gadget 儀表板:
設定檔儲存
我該如何使用 Azure Blob 儲存體 作為 Pyroscope 的後端?
預設情況下, GPU 設定檔文章 中的 Pyroscope 部署會將設定檔儲存在本地檔案系統。 如果 Pod 被重新建立,剖析資料就會遺失。 若要將設定檔持久化儲存,請將 Pyroscope 設定為使用搭配 Microsoft Entra 工作負載 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 版本中使用的服務帳號名稱相符。 否則,Pyroscope 無法認證到 Azure Blob 儲存體。
使用 Azure Blob 儲存體 後端部署 Pyroscope
在 啟用 Pyroscope 的輪廓視覺化中,不要用 Helm 指令,而是執行以下指令。 此配置使用 Azure Blob 儲存體,建立服務帳號,並在 Pyroscope 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
確認艙體是否運作中:
kubectl get pods -n gadget pyroscope-0
繼續閱讀將 Pyroscope 連接至 Azure 受控 Grafana。
Note
Helm 值鍵可以在不同版本的圖表間改變。 要確認你版本可用的金鑰,請執行 helm show values oci://ghcr.io/grafana/helm-charts/pyroscope --version 1.15.0。