設定 Azure Kubernetes Service 的網路可觀察性 (AKS) - BYO Prometheus 和 Grafana
AKS 網路可觀察性可用來收集 AKS 叢集的網路流量資料。 網路可觀察性可讓集中式平臺監視應用程式和網路健康情況。 Prometheus 會收集 AKS 網路可觀察性計量,而 Grafana 會將其可視化。 支援 Cilium 和非 Cilium 資料平面。 在本文中,瞭解如何啟用網路可觀察性附加元件,並使用 BYO Prometheus 和 Grafana 將已擷取的計量可視化。
重要
AKS 網路可檢視性目前為預覽版。 請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。
如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?。
必要條件
具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶。
BYO Prometheus 和 Grafana 的安裝。
在 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
取得叢集認證
az aks get-credentials --name myAKSCluster --resource-group myResourceGroup
在 Grafana 上啟用視覺效果
使用下列範例,在 Prometheus 上設定抓取作業,並為 AKS 叢集啟用 Grafana 上的視覺效果。
注意
下一節需要安裝 Prometheus 和 Grafana。
將下列抓取作業新增至現有的 Prometheus 設定,然後重新啟動 Prometheus 伺服器:
scrape_configs: - job_name: "network-obs-pods" kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_container_name] action: keep regex: kappie(.*) - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] separator: ":" regex: ([^:]+)(?::\d+)? target_label: __address__ replacement: ${1}:${2} action: replace - source_labels: [__meta_kubernetes_pod_node_name] action: replace target_label: instance metric_relabel_configs: - source_labels: [__name__] action: keep regex: (.*)
在 Prometheus 的目標中,確認 network-obs-pods 是否存在。
登入 Grafana 並匯入識別碼 為 18814 的網路可檢視性儀表板。
清除資源
如果您不打算繼續使用此應用程式,請使用下列範例刪除 AKS 叢集和本文中建立的其他資源:
az group delete \
--name myResourceGroup
下一步
在本操作說明文章中,您已瞭解如何安裝和啟用 AKS 叢集的 AKS 網路可檢視性。
如需 AKS 網路可檢視性的詳細資訊,請參閱什麼是 Azure Kubernetes Service (AKS) 網路可檢視性?。
若要建立具有網路可觀察性和受控 Prometheus 和 Grafana 的 AKS 叢集,請參閱 設定 Azure Kubernetes Service (AKS) Azure 受控 Prometheus 和 Grafana 的網路可檢視性。