設定 Azure Kubernetes Service 的網路可觀察性 (AKS) - Azure 受控 Prometheus 和 Grafana
AKS 網路可觀察性可用來收集 AKS 叢集的網路流量資料。 網路可觀察性可讓集中式平臺監視應用程式和網路健康情況。 Prometheus 會收集 AKS 網路可觀察性計量,而 Grafana 會將其可視化。 支援 Cilium 和非 Cilium 資料平面。 在本文中,了解如何啟用網路可觀察性附加元件,並使用 Azure 受控 Prometheus 和 Grafana 將已擷取的計量可視化。
重要
AKS 網路可觀察性目前為預覽狀態。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。
如需 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。
安裝 aks-preview
Azure CLI 延伸模組
重要
AKS 預覽功能可透過自助服務,以加入方式使用。 預覽會以「現狀」和「可供使用時」提供,其其不受服務等級協定和有限瑕疵擔保所保護。 客戶支援部門會盡最大努力,部分支援 AKS 預覽。 因此,這些功能不適合實際執行用途。 如需詳細資訊,請參閱下列支援文章:
# Install the aks-preview extension
az extension add --name aks-preview
# Update the extension to make sure you have the latest version installed
az extension update --name aks-preview
註冊 NetworkObservabilityPreview
功能旗標
az feature register --namespace "Microsoft.ContainerService" --name "NetworkObservabilityPreview"
使用 az feature show 來檢查功能旗標的註冊狀態:
az feature show --namespace "Microsoft.ContainerService" --name "NetworkObservabilityPreview"
等候功能在發行項之前先顯示 [已註冊]。
{
"id": "/subscriptions/23250d6d-28f0-41dd-9776-61fc80805b6e/providers/Microsoft.Features/providers/Microsoft.ContainerService/features/NetworkObservabilityPreview",
"name": "Microsoft.ContainerService/NetworkObservabilityPreview",
"properties": {
"state": "Registering"
},
"type": "Microsoft.Features/providers/features"
}
註冊此功能時,請使用 az provider register 重新整理 Microsoft.ContainerService 資源提供者的註冊:
az provider register -n Microsoft.ContainerService
建立資源群組
資源群組是在其中部署與管理 Azure 資源的邏輯容器。 使用 az group create 命令來建立資源群組。 下列範例會在 eastus 位置建立名為 myResourceGroup 的資源群組:
az group create \
--name myResourceGroup \
--location eastus
建立 AKS 叢集
使用 az aks create 建立 AKS 叢集。 下列範例會在 myResourceGroup 的資源群組中,建立名為 myAKSCluster 的 AKS 叢集:
非 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 \
--enable-network-observability
現有的叢集
使用 az aks update 來啟用現有叢集的網路可檢視性。
az aks update \
--resource-group myResourceGroup \
--name myAKSCluster \
--enable-network-observability
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
從左側導覽功能表中選取 [儀錶板],開啟 [Managed Prometheus] 資料夾下的 [Kubernetes / 網路] 儀錶板。
檢查 Kubernetes / Networking Grafana 儀錶板中的計量是否可見。 如果未顯示計量,請將時間範圍變更為右上方下拉式方塊中的 [過去 15 分鐘]。
清除資源
如果您不打算繼續使用此應用程式,請使用下列範例刪除 AKS 叢集和本文中建立的其他資源:
az group delete \
--name myResourceGroup
下一步
在本操作說明文章中,您已了解如何安裝和啟用 AKS 叢集的 AKS 網路可檢視性。
如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?。
若要建立具有網路可觀察性和 BYO Prometheus 和 Grafana 的 AKS 叢集,請參閱 設定 Azure Kubernetes Service (AKS) BYO Prometheus 和 Grafana 的網路可檢視性。