在 Azure Monitor 中为 Kubernetes 监视启用专用链接

Azure 专用链接支持使用专用终结点访问虚拟网络中的 Azure 平台即服务 (PaaS) 资源。 Azure Monitor 专用链接范围 (AMPLS) 将专用终结点连接到一组 Azure Monitor 资源,以定义监视网络的边界。 将专用终结点用于托管 Prometheus/容器见解和 Azure Monitor 工作区/Log Analytics 工作区,可以允许虚拟网络 (VNet) 上的客户端通过专用链接安全地引入数据。

本文介绍如何配置容器见解和托管的 Prometheus 以使用专用链接从 Azure Kubernetes 服务 (AKS) 群集引入数据。

托管的 Prometheus(Azure Monitor 工作区)

按照以下步骤设置将 Prometheus 指标从私有 AKS 群集引入到 Azure Monitor 工作区。

概念概述

  • 专用终结点是虚拟网络(VNet)中 Azure 服务的特殊网络接口。 为 Azure Monitor 工作区创建专用终结点时,它会在 VNet 上的客户端和工作区之间提供安全连接。 有关详细信息,请参阅 专用终结点
  • 使用 Azure 专用链接,可以使用专用终结点将 Azure 平台即服务(PaaS)资源安全地链接到虚拟网络。 Azure Monitor 使用名为 Azure Monitor 专用链接范围或 AMPLS 的单个专用链接连接,使虚拟网络中的每个客户端能够与 Log Analytics 工作区、Azure Monitor 工作区等所有 Azure Monitor 资源(而不是创建多个专用链接)进行连接。 有关详细信息,请参阅 Azure Monitor 专用链接范围(AMPLS)

该图显示通过专用链接进行引入的概述。

若要设置使用专用终结点将托管 Prometheus 指标从虚拟网络引入到 Azure Monitor 工作区,请按照以下大致步骤进行操作:

  • 创建 Azure Monitor 专用链接范围(AMPLS),并将其与 Azure Monitor 工作区的数据收集终结点连接。
  • 将 AMPLS 连接到为专用 AKS 群集的虚拟网络设置的专用终结点。

先决条件

启用了托管 Prometheus 的专用 AKS 群集。 作为托管 Prometheus 功能启用的一部分,还设置了一个 Azure Monitor 工作区。 有关详细信息,请参阅在 AKS 中启用托管 Prometheus

设置从专用 AKS 群集到 Azure Monitor 工作区的数据引入

1.为 Azure Monitor 工作区创建 AMPLS

使用 Azure 托管 Prometheus 收集的指标将引入并存储在 Azure Monitor 工作区中,因此必须通过专用链接访问工作区。 为此,请创建 Azure Monitor 专用链接范围(Azure Monitor Private Link Scope,简称 AMPLS)。

  1. 在 Azure 门户中,搜索 Azure Monitor 专用链接范围,然后单击“ 创建”。

  2. 输入资源组和名称,为引入访问模式选择“专用”。

    显示 AMPLS 配置的屏幕截图。

  3. 单击“查看 + 创建”以创建 AMPLS。

有关安装 AMPLS 的详细信息,请参阅 “为 Azure Monitor 配置专用链接”。

2.将 AMPLS 连接到 Azure Monitor 工作区的数据收集终结点

托管的 Prometheus 数据引入的专用链接在存储数据的 Azure Monitor 工作区的数据收集终结点 (DCE) 上配置。 若要标识与 Azure Monitor 工作区关联的 DCE,请在 Azure 门户中从 Azure Monitor 工作区中选择数据收集终结点。

  1. 在 Azure 门户中,搜索在为专用 AKS 群集启用托管 Prometheus 时创建的 Azure Monitor 工作区。 记下数据收集终结点名称。

    显示 Azure Monitor 工作区的数据收集终结点页的屏幕截图。

  2. 现在,在 Azure 门户中,搜索在上一步中创建的 AMPLS。 转到 AMPLS 概述页,单击 “Azure Monitor 资源”,单击“ 添加”,然后连接在上一步中记录的 Azure Monitor 工作区的 DCE。

    显示 DCE 与 AMPLS 的连接的屏幕截图。

2a. 配置 DCE

备注

如果 AKS 群集与 Azure Monitor 工作区不在同一区域,则需要为 Azure Monitor 工作区配置新的数据收集终结点。

仅当 AKS 群集与 Azure Monitor 工作区不在同一区域时,才遵循以下步骤。 如果群集位于同一区域,请跳过此步骤并移动到步骤 3。

  1. 在 AKS 群集所在的同一区域中创建数据收集终结点

  2. 转到 Azure Monitor 工作区,然后单击“概述”页上的“数据收集规则”(DCR)。 此 DCR 的名称与 Azure Monitor 工作区相同。

    屏幕截图显示了 Azure Monitor 工作区的数据收集规则。

  3. 在 DCR 概述页中,单击“ 资源 ”->+“添加”,然后选择 AKS 群集。

    显示如何将 AMW DCR 连接到 AKS 的屏幕截图

  4. 添加 AKS 群集(可能需要刷新页面)后,单击 AKS 群集,然后 编辑终结点的数据收集。 在打开的边栏选项卡中,选择在本部分的步骤 1 中创建的数据收集终结点。 此 DCE 应与 AKS 群集位于同一区域。

    一张截图显示 DCE 的关联关系。

  5. 转到 AMPLS 概述页,单击 Azure Monitor 资源,单击 “添加”,然后连接创建的 DCE。

3.将 AMPLS 连接到 AKS 群集的专用终结点

专用终结点是虚拟网络(VNet)中 Azure 服务的特殊网络接口。 我们现在在专用 AKS 群集的 VNet 中创建专用终结点,并将其连接到 AMPLS,以便安全引入指标。

  1. 在 Azure 门户中,搜索在前面的步骤中创建的 AMPLS。 转到 AMPLS 概述页,单击“ 配置 ->专用终结点连接”,然后选择“ + 专用终结点”。

  2. 选择资源组并输入专用终结点的名称,然后单击“ 下一步”。

  3. “资源 ”部分中,选择 “Microsoft.Monitor/帐户 ”作为“资源类型”、“Azure Monitor 工作区”作为“资源”,然后选择 “prometheusMetrics”。 单击 “下一步”

    显示专用终结点配置的屏幕截图

  4. “虚拟网络 ”部分中,选择 AKS 群集的虚拟网络。 可以在门户中的 AKS 概述 - 设置 ->> 网络 -> 虚拟网络集成中找到此内容。

4.验证指标是否已引入 Azure Monitor 工作区

验证专用 AKS 群集中的 Prometheus 指标是否已引入 Azure Monitor 工作区:

  1. 在 Azure 门户中,搜索 Azure Monitor 工作区,并转到 “监视 ->指标”。
  2. 在指标资源管理器中,查询指标并验证是否能够查询。

备注

从专用 AKS 群集引入

如果选择使用 Azure 防火墙来限制群集的流出量,可以实施以下其中一项:

  • 打开公共引入终结点的路径。 使用以下两个终结点更新路由表:
    • *.handler.control.monitor.azure.cn
    • *.ingest.monitor.azure.cn
  • 启用 Azure 防火墙以访问用于数据引入的 Azure Monitor 专用链接范围和 DCE。

使用以下步骤通过专用链接虚拟网络和 Azure Monitor 专用链接范围为 Kubernetes 群集设置远程写入。

  1. 创建 Azure 虚拟网络。
  2. 将本地群集配置为使用 VPN 网关或具有专用对等互连的 ExpressRoutes 连接到 Azure VNET。
  3. 创建 Azure Monitor 专用链接范围。
  4. 将 Azure Monitor 专用链接范围连接到本地群集使用的虚拟网络中的专用终结点。 此专用终结点用于访问 DCE。
  5. 从门户中的 Azure Monitor 工作区,在 Azure Monitor 工作区菜单中选择“数据收集终结点”
  6. 至少有一个 DCE 与工作区同名。 单击 DCE 可打开其详细信息。
  7. 选择 DCE 的“网络隔离”页。
  8. 单击“添加”并选择 Azure Monitor 专用链接范围。 传播设置需要几分钟。 完成后,专用 AKS 群集中的数据会通过专用链接引入 Azure Monitor 工作区。

容器见解(Log Analytics 工作区)

容器见解的数据存储在 Log Analytics 工作区中,因此必须通过专用链接访问该工作区。

备注

本部分介绍如何使用 CLI 为容器见解启用专用链接。 有关使用 ARM 模板的详细信息,请参阅启用容器见解并记下参数 useAzureMonitorPrivateLinkScopeazureMonitorPrivateLinkScopeResourceId

先决条件

  • 本文介绍如何将群集连接到现有的 Azure Monitor 专用链接范围 (AMPLS)。 按照配置专用链接中的指导创建 AMPLS。
  • Azure CLI 2.61.0 或更高版本。

使用托管标识身份验证的群集

具有默认 Log Analytics 工作区的现有 AKS 群集

az aks enable-addons --addon monitoring --name <cluster-name> --resource-group <cluster-resource-group-name> --ampls-resource-id "<azure-monitor-private-link-scope-resource-id>"

示例:

az aks enable-addons --addon monitoring --name "my-cluster" --resource-group "my-resource-group" --workspace-resource-id "/subscriptions/my-subscription/resourceGroups/my-resource-group/providers/Microsoft.OperationalInsights/workspaces/my-workspace" --ampls-resource-id "/subscriptions/my-subscription /resourceGroups/my-resource-group/providers/microsoft.insights/privatelinkscopes/my-ampls-resource"

具有现有 Log Analytics 工作区的现有 AKS 群集

az aks enable-addons --addon monitoring --name <cluster-name> --resource-group <cluster-resource-group-name> --workspace-resource-id <workspace-resource-id> --ampls-resource-id "<azure-monitor-private-link-scope-resource-id>"

示例:

az aks enable-addons --addon monitoring --name "my-cluster" --resource-group "my-resource-group" --workspace-resource-id "/subscriptions/my-subscription/resourceGroups/my-resource-group/providers/Microsoft.OperationalInsights/workspaces/my-workspace" --ampls-resource-id "/subscriptions/my-subscription /resourceGroups/ my-resource-group/providers/microsoft.insights/privatelinkscopes/my-ampls-resource"

新 AKS 群集

az aks create --resource-group rgName --name clusterName --enable-addons monitoring --workspace-resource-id "workspaceResourceId" --ampls-resource-id "azure-monitor-private-link-scope-resource-id"

示例:

az aks create --resource-group "my-resource-group" --name "my-cluster" --enable-addons monitoring --workspace-resource-id "/subscriptions/my-subscription/resourceGroups/my-resource-group/providers/Microsoft.OperationalInsights/workspaces/my-workspace" --ampls-resource-id "/subscriptions/my-subscription /resourceGroups/ my-resource-group/providers/microsoft.insights/privatelinkscopes/my-ampls-resource"

使用旧身份验证的群集

如果群集未使用托管标识身份验证,请使用以下过程通过 Azure 专用链接 将群集连接到 Log Analytics 工作区来启用网络隔离。 这需要用到专用 AKS 群集

  1. 按照创建专用 Azure Kubernetes 服务群集中的指导创建专用 AKS 群集。

  2. 在 Log Analytics 工作区上禁用公共引入。

    使用以下命令在现有工作区上禁用公共引入。

    az monitor log-analytics workspace update --resource-group <azureLogAnalyticsWorkspaceResourceGroup> --workspace-name <azureLogAnalyticsWorkspaceName> --ingestion-access Disabled
    

    使用以下命令创建禁用公共引入的新工作区。

    az monitor log-analytics workspace create --resource-group <azureLogAnalyticsWorkspaceResourceGroup> --workspace-name <azureLogAnalyticsWorkspaceName> --ingestion-access Disabled
    
  3. 按照配置专用链接中的说明配置专用链接。 将引入访问权限设置为“公共”,然后在创建专用终结点之后但在启用监视之前将其设置为“专用”。 专用链接资源区域必须与 AKS 群集区域相同。

  4. 启用对 AKS 群集的监视。

    az aks enable-addons -a monitoring --resource-group <AKSClusterResourceGorup> --name <AKSClusterName> --workspace-resource-id <workspace-resource-id> --enable-msi-auth-for-monitoring false
    

后续步骤