如何停止使用用于容器的 Azure Monitor 监视 Azure Kubernetes 服务 (AKS)How to stop monitoring your Azure Kubernetes Service (AKS) with Azure Monitor for containers

启用监视 AKS 群集后,如果决定不再监视它,可以停止监视群集。After you enable monitoring of your AKS cluster, you can stop monitoring the cluster if you decide you no longer want to monitor it. 本文介绍如何使用 Azure CLI 或提供的 Azure 资源管理器模板完成此操作。This article shows how to accomplish this using the Azure CLI or with the provided Azure Resource Manager templates.

Azure CLIAzure CLI

使用 az aks disable-addons 命令禁用容器的 Azure Monitor。Use the az aks disable-addons command to disable Azure Monitor for containers. 该命令从群集节点中删除代理,它不会删除已收集并存储在 Azure Monitor 资源中的解决方案或数据。The command removes the agent from the cluster nodes, it does not remove the solution or the data already collected and stored in your Azure Monitor resource.

az aks disable-addons -a monitoring -n MyExistingManagedCluster -g MyExistingManagedClusterRG

若要重新启用对群集的监视,请参阅使用 Azure CLI 启用监视To re-enable monitoring for your cluster, see Enable monitoring using Azure CLI.

Azure 资源管理器模板Azure Resource Manager template

下面提供了两个 Azure 资源管理器模板,以支持在资源组中一致且重复地删除解决方案资源。Provided are two Azure Resource Manager template to support removing the solution resources consistently and repeatedly in your resource group. 一个是 JSON 模板,用于指定配置为“停止监视”,另一个模板包含配置的参数值,用于指定在其中部署群集的 AKS 群集资源 ID 和资源组。One is a JSON template specifying the configuration to stop monitoring and the other contains parameter values that you configure to specify the AKS cluster resource ID and resource group that the cluster is deployed in.

如果不熟悉使用模板部署资源的概念,请参阅:If you're unfamiliar with the concept of deploying resources by using a template, see:

备注

模板需要部署在群集所在的资源组中。The template needs to be deployed in the same resource group of the cluster. 如果在使用此模板时省略任何其他属性或加载项,则可能导致从群集中删除这些属性或加载项。If you omit any other properties or add-ons when using this template, it can result in their removal from the cluster. 例如,enableRBAC(用于群集中实施的 RBAC 策略),或 aksResourceTagValues(如果为 AKS 群集指定了标记)。For example, enableRBAC for RBAC policies implemented in your cluster, or aksResourceTagValues if tags are specified for the 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.27 版或更高版本。You must be running the Azure CLI version 2.0.27 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.

创建模板Create template

  1. 将以下 JSON 语法复制并粘贴到文件中:Copy and paste the following JSON syntax into your file:

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "aksResourceId": {
           "type": "string",
           "metadata": {
             "description": "AKS Cluster Resource ID"
           }
       },
      "aksResourceLocation": {
        "type": "string",
        "metadata": {
           "description": "Location of the AKS resource e.g. \"China East2\""
         }
       },
    "aksResourceTagValues": {
      "type": "object",
      "metadata": {
        "description": "Existing all tags on AKS Cluster Resource"
        }
      }
     },
    "resources": [
      {
        "name": "[split(parameters('aksResourceId'),'/')[8]]",
        "type": "Microsoft.ContainerService/managedClusters",
        "location": "[parameters('aksResourceLocation')]",
        "tags": "[parameters('aksResourceTagValues')]",
        "apiVersion": "2018-03-31",
        "properties": {
          "mode": "Incremental",
          "id": "[parameters('aksResourceId')]",
          "addonProfiles": {
            "omsagent": {
              "enabled": false,
              "config": null
            }
           }
         }
       }
      ]
    }
    
  2. 将此文件以“OptOutTemplate.json”文件名保存到本地文件夹 。Save this file as OptOutTemplate.json to a local folder.

  3. 将以下 JSON 语法粘贴到文件中:Paste the following JSON syntax into your file:

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "aksResourceId": {
          "value": "/subscriptions/<SubscriptionID>/resourcegroups/<ResourceGroup>/providers/Microsoft.ContainerService/managedClusters/<ResourceName>"
        },
        "aksResourceLocation": {
          "value": "<aksClusterRegion>"
        },
        "aksResourceTagValues": {
          "value": {
            "<existing-tag-name1>": "<existing-tag-value1>",
            "<existing-tag-name2>": "<existing-tag-value2>",
            "<existing-tag-nameN>": "<existing-tag-valueN>"
          }
        }
      }
    }
    
  4. 使用可在选定群集的“属性”页面上找到的 AKS 群集的值,编辑 aksResourceIdaksResourceLocation 的值 。Edit the values for aksResourceId and aksResourceLocation by using the values of the AKS cluster, which you can find on the Properties page for the selected cluster.

    容器属性页面

    位于“属性”页时,还请复制“工作区资源 ID” 。While you are on the Properties page, also copy the Workspace Resource ID. 如果决定稍后删除 Log Analytics 工作区,则需要此值。This value is required if you decide you want to delete the Log Analytics workspace later. 不在此流程中执行删除 Log Analytics 工作区的操作。Deleting the Log Analytics workspace is not performed as part of this process.

    编辑 aksResourceTagValues 的值,以匹配为 AKS 群集指定的现有标记值。Edit the values for aksResourceTagValues to match the existing tag values specified for the AKS cluster.

  5. 将此文件以“OptOutParam.json”文件名保存到本地文件夹 。Save this file as OptOutParam.json to a local folder.

  6. 已做好部署此模板的准备。You are ready to deploy this template.

使用 Azure CLI 删除解决方案Remove the solution using Azure CLI

在 Linux 上使用 Azure CLI 执行以下命令以删除解决方案并清除 AKS 群集上的配置。Execute the following command with Azure CLI on Linux to remove the solution and clean up the configuration on your AKS cluster.

az cloud set --name AzureChinaCloud
az login   
az account set --subscription "Subscription Name"
az group deployment create --resource-group <ResourceGroupName> --template-file ./OptOutTemplate.json --parameters @./OptOutParam.json  

配置更改可能需要几分钟才能完成。The configuration change can take a few minutes to complete. 完成后,系统会返回包含结果的消息,如下所示:When it's completed, a message similar to the following that includes the result is returned:

ProvisioningState       : Succeeded

使用 PowerShell 删除解决方案Remove the solution using PowerShell

备注

本文进行了更新,以便使用新的 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.

在包含模板的文件夹中执行以下 PowerShell 命令以删除解决方案并从 AKS 群集中清除配置。Execute the following PowerShell commands in the folder containing the template to remove the solution and clean up the configuration from your AKS cluster.

Connect-AzAccount -Environment AzureChinaCloud
Select-AzSubscription -SubscriptionName <yourSubscriptionName>
New-AzResourceGroupDeployment -Name opt-out -ResourceGroupName <ResourceGroupName> -TemplateFile .\OptOutTemplate.json -TemplateParameterFile .\OptOutParam.json

配置更改可能需要几分钟才能完成。The configuration change can take a few minutes to complete. 完成后,系统会返回包含结果的消息,如下所示:When it's completed, a message similar to the following that includes the result is returned:

ProvisioningState       : Succeeded

后续步骤Next steps

如果创建的工作区仅用于支持监视群集且不再被需要,则需要手动删除它。If the workspace was created only to support monitoring the cluster and it's no longer needed, you have to manually delete it. 如果不熟悉如何删除工作区,请参阅使用 Azure 门户删除 Azure Log Analytics 工作区If you are not familiar with how to delete a workspace, see Delete an Azure Log Analytics workspace with the Azure portal. 不要忘记之前在步骤 4 中复制的“工作区资源 ID”,稍后将会需要 。Don't forget about the Workspace Resource ID copied earlier in step 4, you're going to need that.