共用方式為


設定 Azure Kubernetes Service (AKS) 的網路可檢視性 - Azure 受控 Prometheus 和 Grafana

AKS 網路可觀察性可用來收集 AKS 叢集的網路流量資料。 網路可觀察性可讓集中式平臺監視應用程式和網路健康情況。 Prometheus 會收集 AKS 網路可觀察性計量,而 Grafana 會將其可視化。 支援 Cilium 和非 Cilium 資料平面。 在本文中,了解如何啟用網路可觀察性附加元件,並使用 Azure 受控 Prometheus 和 Grafana 將已擷取的計量可視化。

如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?

必要條件

  • 本文步驟所需的 Azure CLI 最低版本 為 2.44.0。 執行 az --version 以尋找版本。 如果您需要安裝或升級,請參閱安裝 Azure CLI

建立叢集

注意

針對 Kubernetes 版本 >= 1.29,網路可檢視性包含在具有 Azure 受控 Prometheus 的叢集中。 計量抓取是透過 AMA 計量設定檔 (部分機器翻譯) 而定義。

針對較低的 Kubernetes 版本,則須執行額外步驟才能啟用網路可檢視性。

建立資源群組

資源群組是在其中部署與管理 Azure 資源的邏輯容器。 使用 az group create 命令來建立資源群組。 下列範例會在 eastus 位置建立名為 myResourceGroup 的資源群組:

az group create \
    --name myResourceGroup \
    --location eastus

建立 AKS 叢集

使用 az aks create 建立 AKS 叢集。 下列範例各自在 myResourceGroup 資源群組中,建立名為 myAKSCluster 的 AKS 叢集。

範例 1:非 Cilium

在下列範例中,使用 az aks create (部分機器翻譯) 建立非 Cilium AKS 叢集。

az aks create \
    --name myAKSCluster \
    --resource-group myResourceGroup \
    --location eastus \
    --generate-ssh-keys \
    --network-plugin azure \
    --network-plugin-mode overlay \
    --pod-cidr 192.168.0.0/16 \
    --kubernetes-version 1.29

範例 2:Cilium

在下列範例中,使用 az aks create (部分機器翻譯) 建立 Cilium AKS 叢集。

az aks create \
    --name myAKSCluster \
    --resource-group myResourceGroup \
    --generate-ssh-keys \
    --location eastus \
    --max-pods 250 \
    --network-plugin azure \
    --network-plugin-mode overlay \
    --network-dataplane cilium \
    --node-count 2 \
    --pod-cidr 192.168.0.0/16

Azure 受控的 Prometheus 和 Grafana

使用下列範例,為您的 AKS 叢集安裝並啟用 Prometheus 和 Grafana。

建立 Azure 監視器資源

az resource create \
    --resource-group myResourceGroup \
    --namespace microsoft.monitor \
    --resource-type accounts \
    --name myAzureMonitor \
    --location eastus \
    --properties '{}'

建立 Grafana 實例

使用 az grafana create 建立 Grafana 執行個體。 Grafana 執行個體的名稱必須是唯一的。 以 Grafana 執行個體的唯一名稱取代 myGrafana

az grafana create \
    --name myGrafana \
    --resource-group myResourceGroup 

將 Grafana 和 Azure 監視器資源識別碼放在變數中

使用 az grafana show 將 Grafana 資源識別碼放在變數中。 使用 az resource show 將 Azure 監視器資源標識碼放在變數中。 以 Grafana 執行個體名稱取代 myGrafana

grafanaId=$(az grafana show \
                --name myGrafana \
                --resource-group myResourceGroup \
                --query id \
                --output tsv)

azuremonitorId=$(az resource show \
                    --resource-group myResourceGroup \
                    --name myAzureMonitor \
                    --resource-type "Microsoft.Monitor/accounts" \
                    --query id \
                    --output tsv)

使用 az aks update 將 Azure 監視器和 Grafana 資源連結至您的 AKS 叢集。

az aks update \
    --name myAKSCluster \
    --resource-group myResourceGroup \
    --enable-azure-monitor-metrics \
    --azure-monitor-workspace-resource-id $azuremonitorId \
    --grafana-resource-id $grafanaId

取得叢集認證

az aks get-credentials --name myAKSCluster --resource-group myResourceGroup

使用 Grafana 進行視覺化

注意

下一節需要部署 Azure 受控 Prometheus 和 Grafana。

  1. 使用下列範例來確認 Azure 監視器 Pod 正在執行。

    kubectl get po -owide -n kube-system | grep ama-
    
    ama-metrics-5bc6c6d948-zkgc9          2/2     Running   0 (21h ago)   26h
    ama-metrics-ksm-556d86b5dc-2ndkv      1/1     Running   0 (26h ago)   26h
    ama-metrics-node-lbwcj                2/2     Running   0 (21h ago)   26h
    ama-metrics-node-rzkzn                2/2     Running   0 (21h ago)   26h
    ama-metrics-win-node-gqnkw            2/2     Running   0 (26h ago)   26h
    ama-metrics-win-node-tkrm8            2/2     Running   0 (26h ago)   26h
    
  2. 在網頁瀏覽器中瀏覽至您的 Grafana 執行個體。

  3. 我們已建立範例儀表板。 您可以在 [儀表板] > [Azure 受控 Prometheus] > [Kubernetes/網路功能/叢集] 下找到該範例。

  4. 檢查 [Kubernetes/網路功能/叢集] Grafana 儀表板中的計量是否可見。 如果未顯示計量,請將時間範圍變更為右上方下拉式方塊中的 [過去 15 分鐘]。


清除資源

如果您不打算繼續使用此應用程式,請使用下列範例刪除 AKS 叢集和本文中建立的其他資源:

  az group delete \
    --name myResourceGroup

下一步

在本操作說明文章中,您已了解如何設定 AKS 叢集的 AKS 網路可檢視性。