对容器启用 Azure MonitorEnable Azure Monitor for containers

本文概述了可用于为容器设置 Azure Monitor 的选项,这些选项用于监视部署到 Kubernetes 环境并托管在以下位置上的工作负载的性能:This article provides an overview of the options that are available for setting up Azure Monitor for containers to monitor the performance of workloads that are deployed to Kubernetes environments and hosted on:

你也可以监视部署到自托管 Kubernetes 群集的工作负载的性能,这些群集托管在以下位置上:You can also monitor the performance of workloads that are deployed to self-managed Kubernetes clusters hosted on:

可使用以下支持的任意方法为 Kubernetes 的新部署或是一个/多个现有部署启用用于容器的 Azure Monitor:You can enable Azure Monitor for containers for a new deployment or for one or more existing deployments of Kubernetes by using any of the following supported methods:

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

先决条件Prerequisites

首先,请确保你已满足以下要求:Before you start, make sure that you've met the following requirements:

  • 拥有一个 Log Analytics 工作区。You have a Log Analytics workspace.

    用于容器的 Azure Monitor 支持在 Azure 可用产品(按区域) 中列出的区域中的 Log Analytics 工作区。Azure Monitor for containers supports a Log Analytics workspace in the regions that are listed in Products available by region.

    可以在为新 AKS 群集启用监视时创建工作区,或者可让加入体验在 AKS 群集订阅的默认资源组中创建默认的工作区。You can create a workspace when you enable monitoring for your new AKS cluster, or you can let the onboarding experience create a default workspace in the default resource group of the AKS cluster subscription.

    如果你选择自己创建工作区,可通过以下方法创建工作区:If you choose to create the workspace yourself, you can create it through:

  • 需要成为 Log Analytics 参与者组的成员才能启用容器监视。You are a member of the Log Analytics contributor group for enabling container monitoring. 有关如何控制对 Log Analytics 工作区的访问的详细信息,请参阅管理工作区For more information about how to control access to a Log Analytics workspace, see Manage workspaces.

  • 需要成为 AKS 群集资源上所有者组的成员。You are a member of the Owner group on the AKS cluster resource.

    备注

    从 Microsoft Operations Management Suite (OMS) 过渡到 Azure Monitor 期间,Windows 或 Linux 的 OMS 代理称为 Windows 或 Linux 的 Log Analytics 代理。As part of the ongoing transition from Microsoft Operations Management Suite (OMS) to Azure Monitor, the OMS Agent for Windows or Linux will be referred to as the Log Analytics agent for Windows and Log Analytics agent for Linux.

  • 若要查看监视数据,需要在 Log Analytics 工作区(该工作区为容器配置了 Azure Monitor)中拥有 Log Analytics 读者角色。To view the monitoring data, you need to have Log Analytics reader role in the Log Analytics workspace, configured with Azure Monitor for containers.

  • 默认情况下不收集 Prometheus 指标。Prometheus metrics aren't collected by default. 在你配置代理以收集这些指标之前,请务必查看 Prometheus 文档,了解可抓取的数据和支持的方法。Before you configure the agent to collect the metrics, it's important to review the Prometheus documentation to understand what data can be scraped and what methods are supported.

支持的配置Supported configurations

用于容器的 Azure Monitor 正式支持以下配置:Azure Monitor for containers officially supports the following configurations:

网络防火墙要求Network firewall requirements

下表列出了 Azure 中国的代理和防火墙配置信息:The following table lists the proxy and firewall configuration information for Azure China:

代理资源Agent resource 端口Port 说明Description
*.ods.opinsights.azure.cn 443443 数据引入Data ingestion
*.oms.opinsights.azure.cn 443443 OMS 载入OMS onboarding
dc.services.visualstudio.com 443443 用于使用 Azure 公有云 Application Insights 的代理遥测For agent telemetry that uses Azure Public Cloud Application Insights

组件Components

监视性能的能力依赖于专门为用于容器的 Azure Monitor 开发的用于 Linux 的容器化 Log Analytics 代理。Your ability to monitor performance relies on a containerized Log Analytics agent for Linux that's specifically developed for Azure Monitor for containers. 此专用代理可从群集中的所有节点处收集性能和事件数据,并且在部署期间,会自动部署该代理,并注册指定 Log Analytics 工作区。This specialized agent collects performance and event data from all nodes in the cluster, and the agent is automatically deployed and registered with the specified Log Analytics workspace during deployment.

该代理的版本为 microsoft/oms:ciprod04202018 或更高版本,并由采用以下格式的日期表示:mmddyyyy。The agent version is microsoft/oms:ciprod04202018 or later, and it's represented by a date in the following format: mmddyyyy.

备注

随着 Windows Server AKS 支持的正式发布,具有 Windows Server 节点的 AKS 群集在每个单独的 Windows Server 节点上安装了一个预览代理,作为一个 DaemonSet Pod 来收集日志并将其转发给 Log Analytics。With the general availability of Windows Server support for AKS, an AKS cluster with Windows Server nodes has a preview agent installed as a daemonset pod on each individual Windows server node to collect logs and forward it to Log Analytics. 对于性能指标,在标准部署过程中,自动部署在群集中的 Linux 节点会代表群集中的所有 Windows 节点收集数据并将数据转发到 Azure Monitor。For performance metrics, a Linux node that's automatically deployed in the cluster as part of the standard deployment collects and forwards the data to Azure Monitor on behalf all Windows nodes in the cluster.

当该代理的新版本发布时,在承载于 Azure Kubernetes 服务 (AKS) 上的托管 Kubernetes 群集上自动升级该代理。When a new version of the agent is released, it's automatically upgraded on your managed Kubernetes clusters that are hosted on Azure Kubernetes Service (AKS). 若要跟踪已发布的版本,请参阅代理发布公告To track which versions are released, see agent release announcements.

备注

如果你已部署 AKS 群集,可使用 Azure CLI 或提供的 Azure 资源管理器模板启用监视,如后文所示。If you've already deployed an AKS cluster, you've enabled monitoring by using either the Azure CLI or a provided Azure Resource Manager template, as demonstrated later in this article. 不能使用 kubectl 升级、删除、重新部署或部署代理。You can't use kubectl to upgrade, delete, redeploy, or deploy the agent.

模板需要部署在群集所在的资源组中。The template needs to be deployed in the same resource group as the cluster.

若要为容器启用 Azure Monitor,请使用下表中所述的方法之一:To enable Azure Monitor for containers, use one of the methods that's described in the following table:

部署状态Deployment state 方法Method 说明Description
新建 Kubernetes 群集New Kubernetes cluster 使用 Azure CLI 创建 AKS 群集Create an AKS cluster by using the Azure CLI 可以为使用 Azure CLI 创建的新 AKS 群集启用监视。You can enable monitoring for a new AKS cluster that you create by using the Azure CLI.
使用 Terraform 创建 AKS 群集Create an AKS cluster by using Terraform 可以为使用开源工具 Terraform 创建的新 AKS 群集启用监视。You can enable monitoring for a new AKS cluster that you create by using the open-source tool Terraform.
现有 Kubernetes 群集Existing Kubernetes cluster 使用 Azure CLI 启用对 AKS 群集的监视Enable monitoring of an AKS cluster by using the Azure CLI 可以使用 Azure CLI 为已部署的 AKS 群集启用监视。You can enable monitoring for an AKS cluster that's already deployed by using the Azure CLI.
使用 Terraform 为 AKS 群集启用Enable for AKS cluster using Terraform 可以使用开源工具 Terraform 为已部署的 AKS 群集启用监视。You can enable monitoring for an AKS cluster that's already deployed by using the open-source tool Terraform.
从 Azure Monitor 为 AKS 群集启用Enable for AKS cluster from Azure Monitor 可以从 Azure Monitor 的多群集页为一个或多个已部署的 AKS 群集启用监视。You can enable monitoring for one or more AKS clusters that are already deployed from the multi-cluster page in Azure Monitor.
从 AKS 群集启用Enable from AKS cluster 可以直接从 Azure 门户中的 AKS 群集启用监视。You can enable monitoring directly from an AKS cluster in the Azure portal.
使用 Azure 资源管理器模板为 AKS 群集启用Enable for AKS cluster using an Azure Resource Manager template 可以使用预先配置的 Azure 资源管理器模板为 AKS 群集启用监视。You can enable monitoring for an AKS cluster by using a preconfigured Azure Resource Manager template.
为混合 Kubernetes 群集启用Enable for hybrid Kubernetes cluster 可以为托管在 Azure Stack 上的 AKS 引擎或为托管在本地的 Kubernetes 群集启用监视。You can enable monitoring for the AKS engine that's hosted on Azure Stack or for a Kubernetes cluster that's hosted on-premises.

后续步骤Next steps

你现在已启用监视,接着可开始分析 Azure Kubernetes 服务 (AKS)、Azure Stack 或其他环境中托管的 Kubernetes 群集的性能。Now that you've enabled monitoring, you can begin analyzing the performance of your Kubernetes clusters that are hosted on Azure Kubernetes Service (AKS), Azure Stack, or another environment. 若要了解如何使用用于容器的 Azure Monitor,请参阅查看 Kubernetes 群集性能To learn how to use Azure Monitor for containers, see View Kubernetes cluster performance.