启用对新的 Azure Kubernetes 服务 (AKS) 群集的监视Enable monitoring of a new Azure Kubernetes Service (AKS) cluster

本文介绍如何设置用于容器的 Azure Monitor,以监视准备在订阅中部署的 Azure Kubernetes 服务上托管的托管 Kubernetes 群集。This article describes how to set up Azure Monitor for containers to monitor managed Kubernetes cluster hosted on Azure Kubernetes Service that you are preparing to deploy in your subscription.

可以使用下述支持的方法之一,启用对 AKS 群集的监视:You can enable monitoring of an AKS cluster using one of the supported methods:

  • Azure CLIAzure CLI
  • TerraformTerraform

启用 Azure CLIEnable using Azure CLI

若要使用 Azure CLI 对新建的 AKS 群集启用监视,请遵循快速入门文章的创建 AKS 群集部分中所述的步骤。To enable monitoring of a new AKS cluster created with Azure CLI, follow the step in the quickstart article under the section Create AKS cluster.

备注

如果选择使用 Azure CLI,首先需要在本地安装和使用 CLI。If you choose to use the Azure CLI, you first need to install and use the CLI locally. 必须运行 Azure CLI 2.0.74 或更高版本。You must be running the Azure CLI version 2.0.74 or later. 若要确定版本,请运行 az --versionTo identify your version, run az --version. 如果需要安装或升级 Azure CLI,请参阅安装 Azure CLIIf you need to install or upgrade the Azure CLI, see Install the Azure CLI. 如果你安装了 aks-preview CLI 扩展 0.4.12 或更高版本,请删除你为启用预览扩展所做的任何更改,因为这些更改会重写默认的 Azure CLI 行为。If you have installed the aks-preview CLI extension version 0.4.12 or higher, remove any changes you have made to enable a preview extension as it can override the default Azure CLI behavior.

使用 TerraformEnable using Terraform

如果正在使用 Terraform 部署新的 AKS 群集,请指定配置文件所需的参数,以便在未指定现有工作区时创建 Log Analytics 工作区If you are deploying a new AKS cluster using Terraform, you specify the arguments required in the profile to create a Log Analytics workspace if you do not chose to specify an existing one.

备注

如果选择使用 Terraform,则必须运行 Terraform Azure RM 提供程序 1.17.0 版或更高版本。If you choose to use Terraform, you must be running the Terraform Azure RM Provider version 1.17.0 or above.

要将用于容器的 Azure Monitor 添加到工作区,请参阅 azurerm_log_analytics_solution,并通过纳入 addon_profile,以及指定 oms_agent,完成配置文件 。To add Azure Monitor for containers to the workspace, see azurerm_log_analytics_solution and complete the profile by including the addon_profile and specify oms_agent.

启用监视并成功完成所有配置任务后,可通过两种方法监视群集性能:After you've enabled monitoring and all configuration tasks are completed successfully, you can monitor the performance of your cluster in either of two ways:

  • 直接在 AKS 群集的左侧窗格中选择“见解”。Directly in the AKS cluster by selecting Insights in the left pane.

  • 在选定群集的 AKS 群集页面中选择“监视容器见解”磁贴 。By selecting the Monitor Container insights tile in the AKS cluster page for the selected cluster. 在 Azure Monitor 的左侧窗格中选择“见解”。In Azure Monitor, in the left pane, select Insights.

    用于在 AKS 中为容器选择 Azure Monitor 的选项

启用监视后,可能需要约 15 分钟才能查看群集的运行状况指标。After you've enabled monitoring, it might take about 15 minutes before you can view health metrics for the cluster.

验证代理和解决方案部署Verify agent and solution deployment

如果代理版本为 06072018 或更高版本,则可验证代理和解决方案是否均已成功部署。With agent version 06072018 or later, you can verify that both the agent and the solution were deployed successfully. 如果是早期版本的代理,则只能验证代理的部署情况。With earlier versions of the agent, you can verify only agent deployment.

06072018 版或更高版本的代理Agent version 06072018 or later

运行以下命令,验证代理是否已成功部署。Run the following command to verify that the agent is deployed successfully.

kubectl get ds omsagent --namespace=kube-system

输出应如下所示,指明其已正确部署:The output should resemble the following, which indicates that it was deployed properly:

User@aksuser:~$ kubectl get ds omsagent --namespace=kube-system 
NAME       DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE
omsagent   2         2         2         2            2           beta.kubernetes.io/os=linux   1d

若要验证解决方案的部署,请运行以下命令:To verify deployment of the solution, run the following command:

kubectl get deployment omsagent-rs -n=kube-system

输出应如下所示,指明其已正确部署:The output should resemble the following, which indicates that it was deployed properly:

User@aksuser:~$ kubectl get deployment omsagent-rs -n=kube-system 
NAME       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE    AGE
omsagent   1         1         1            1            3h

代理版本低于 06072018Agent version earlier than 06072018

若要验证 06072018 之前发布的 Log Analytics 代理版本是否已正确部署,请运行以下命令:To verify that the Log Analytics agent version released before 06072018 is deployed properly, run the following command:

kubectl get ds omsagent --namespace=kube-system

输出应如下所示,指明其已正确部署:The output should resemble the following, which indicates that it was deployed properly:

User@aksuser:~$ kubectl get ds omsagent --namespace=kube-system 
NAME       DESIRED   CURRENT   READY     UP-TO-DATE   AVAILABLE   NODE SELECTOR                 AGE
omsagent   2         2         2         2            2           beta.kubernetes.io/os=linux   1d

使用 CLI 查看配置View configuration with CLI

使用 aks show 命令获取详细信息,例如,解决方案是否已启用、Log Analytics 工作区 resourceID 是什么,以及有关群集的摘要详细信息。Use the aks show command to get details such as is the solution enabled or not, what is the Log Analytics workspace resourceID, and summary details about the cluster.

az aks show -g <resourceGroupofAKSCluster> -n <nameofAksCluster>

片刻之后,该命令将会完成,并返回有关解决方案的 JSON 格式信息。After a few minutes, the command completes and returns JSON-formatted information about solution. 命令结果应显示监视加载项配置文件,并类似于以下示例输出:The results of the command should show the monitoring add-on profile and resembles the following example output:

"addonProfiles": {
    "omsagent": {
      "config": {
        "logAnalyticsWorkspaceResourceID": "/subscriptions/<WorkspaceSubscription>/resourceGroups/<DefaultWorkspaceRG>/providers/Microsoft.OperationalInsights/workspaces/<defaultWorkspaceName>"
      },
      "enabled": true
    }
  }

后续步骤Next steps

  • 如果在尝试载入解决方案时遇到问题,请查看故障排除指南If you experience issues while attempting to onboard the solution, review the troubleshooting guide

  • 启用监视以收集 AKS 群集及其上运行的工作负荷的运行状况和资源利用率,了解如何使用用于容器的 Azure Monitor。With monitoring enabled to collect health and resource utilization of your AKS cluster and workloads running on them, learn how to use Azure Monitor for containers.