你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure Kubernetes 服务 (AKS) 的网络可观测性设置 - BYO Prometheus 和 Grafana

AKS 网络可观测性用于收集 AKS 群集的网络流量数据。 网络可观测性支持用于监视应用程序和网络运行状况的集中式平台。 Prometheus 负责收集 AKS 网络可观测性指标,而 Grafana 将它们可视化。 支持 Cilium 和非 Cilium 数据平面。 本文介绍如何启用网络可观测性加载项,并使用 BYO Prometheus 和 Grafana 可视化抓取的指标。

注意

从 Kubernetes 版本 1.29 开始,网络可观测性功能不再支持自带 (BYO) Prometheus 和 Grafana。 但是,仍可以使用 Azure 托管 Prometheus 和 Grafana 产品/服务启用它

重要

AKS 网络可观测性目前处于预览状态。 有关 beta 版本、预览版或尚未正式发布的版本的 Azure 功能所适用的法律条款,请参阅 Microsoft Azure 预览版的补充使用条款

有关 AKS 网络可观测性的详细信息,请参阅什么是 Azure Kubernetes 服务 (AKS) 网络可观测性?

先决条件

  • 具有活动订阅的 Azure 帐户。 免费创建帐户

  • BYO Prometheus 和 Grafana 的安装。

  • 本文中的步骤所需的 Azure CLI 最低版本为 2.44.0。 运行 az --version 即可查找版本。 如果需要进行安装或升级,请参阅安装 Azure CLI

安装 Azure CLI aks-preview 扩展

重要

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 上配置抓取作业,并在 Grafana 上为 AKS 群集启用可视化效果。

注意

以下部分要求安装 Prometheus 和 Grafana。

  1. 将以下抓取作业添加到现有 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: (.*)
    
  2. 在 Prometheus 的“目标”中,验证 network-obs-pods 是否存在。

  3. 登录到 Grafana 并使用 ID 18814 导入网络可观测性仪表板。

清理资源

如果不打算继续使用此应用程序,请使用以下示例删除本文中创建的 AKS 群集和其他资源:

  az group delete \
    --name myResourceGroup

后续步骤

本操作指南文章介绍了如何为 AKS 群集安装和启用 AKS 网络可观测性。