設定 Azure Kubernetes Service (AKS) 的網路可檢視性 - Azure 受控 Prometheus 和 Grafana
AKS 網路可觀察性可用來收集 AKS 叢集的網路流量資料。 網路可觀察性可讓集中式平臺監視應用程式和網路健康情況。 Prometheus 會收集 AKS 網路可觀察性計量,而 Grafana 會將其可視化。 支援 Cilium 和非 Cilium 資料平面。 在本文中,了解如何啟用網路可觀察性附加元件,並使用 Azure 受控 Prometheus 和 Grafana 將已擷取的計量可視化。
如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?。
必要條件
- 具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶。
在 Azure Cloud Shell 中使用 Bash 環境。 如需詳細資訊,請參閱 Azure Cloud Shell 中的 Bash 快速入門。
若要在本地執行 CLI 參考命令,請安裝 Azure CLI。 若您在 Windows 或 macOS 上執行,請考慮在 Docker 容器中執行 Azure CLI。 如需詳細資訊,請參閱〈如何在 Docker 容器中執行 Azure CLI〉。
如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。 請遵循您終端機上顯示的步驟,完成驗證程序。 如需其他登入選項,請參閱使用 Azure CLI 登入。
出現提示時,請在第一次使用時安裝 Azure CLI 延伸模組。 如需擴充功能詳細資訊,請參閱使用 Azure CLI 擴充功能。
執行 az version 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade。
- 本文步驟所需的 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)
將 Azure 監視器和 Grafana 連結至 AKS 叢集
使用 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。
使用下列範例來確認 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
在網頁瀏覽器中瀏覽至您的 Grafana 執行個體。
我們已建立範例儀表板。 您可以在 [儀表板] > [Azure 受控 Prometheus] > [Kubernetes/網路功能/叢集] 下找到該範例。
檢查 [Kubernetes/網路功能/叢集] Grafana 儀表板中的計量是否可見。 如果未顯示計量,請將時間範圍變更為右上方下拉式方塊中的 [過去 15 分鐘]。
清除資源
如果您不打算繼續使用此應用程式,請使用下列範例刪除 AKS 叢集和本文中建立的其他資源:
az group delete \
--name myResourceGroup
下一步
在本操作說明文章中,您已了解如何設定 AKS 叢集的 AKS 網路可檢視性。
如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?。
若您對更細微的網路可檢視性和其他進階功能感興趣,請參閱什麼是適用於 Azure Kubernetes Service (AKS) 的進階容器網路服務 ? (部分機器翻譯)。