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

禁用对 Kubernetes 群集的监视

使用以下方法从 Kubernetes 群集中删除容器见解Prometheus

所需的权限

  • 你至少需要群集的参与者访问权限。

禁用容器见解

AKS 群集

使用 az aksdisable-addons CLI 命令禁用群集上的容器见解。 该命令从群集节点中删除代理。 它不会删除已收集并存储在群集的 Log Analytics 工作区中的数据。

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

也可使用下面的 ARM 模板来删除容器见解。

{
  "$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. \"East US\""
            }
        },
      "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
        }
        }
      }
    }
  ]
}

已启用 Arc 的 Kubernetes 群集

以下 PowerShell 和 Bash 脚本可用于从已启用 Arc 的 Kubernetes 群集中删除容器见解。 可以通过运行 kubectl config get-contexts 命令获取群集的 kube-context。 若要使用当前上下文,则请不要指定此参数。

PowerShell:disable-monitoring.ps1

# Use current context
.\disable-monitoring.ps1 -clusterResourceId <cluster-resource-id>

# Specify kube-context
.\disable-monitoring.ps1 -clusterResourceId <cluster-resource-id> -kubeContext <kube-context>

Bash:disable-monitoring.sh

# Use current context
bash disable-monitoring.sh --resource-id $AZUREARCCLUSTERRESOURCEID 

# Specify kube-context
bash disable-monitoring.sh --resource-id $AZUREARCCLUSTERRESOURCEID --kube-context $KUBECONTEXT

使用 Helm 删除容器见解

以下步骤适用于以下环境:

  • Azure 和 Azure Stack 的 AKS 引擎
  • OpenShift 版本 4 及更高版本
  1. 运行以下 helm 命令,以确定群集上安装的容器见解 helm chart 版本

    helm list
    

    输出类似于:

    NAME                            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                           APP VERSION
    azmon-containers-release-1      default         3               2020-04-21 15:27:24.1201959 -0700 PDT   deployed        azuremonitor-containers-2.7.0   7.0.0-1
    

    azmon-containers-release-1 表示用于“容器见解”的 helm 图表版本。

  2. 若要删除图表版本,请运行以下 helm 命令。

    helm delete <releaseName>

    示例:

    helm delete azmon-containers-release-1

    这将从群集中移除发布。 用户可通过再次运行命令 helm list 来验证。

    NAME                            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                           APP VERSION
    

配置更改可能需要几分钟才能完成。 由于 Helm 会在用户删除发布后对其进行跟踪,因此可以审核群集的历史记录,甚至还可以使用 helm rollback 撤消删除发布。

禁用 Prometheus

使用以下带 --disable-azure-monitor-metrics 参数的 az aks update Azure CLI 命令删除 AKS 群集中的指标加载项,或使用带有 --name azuremonitor-metrics 参数的 az k8s-extension delete Azure CLI 命令删除已启用 Arc 的群集中的指标加载项,并停止将 Prometheus 指标发送到 Azure Monitor适用于 Prometheus 的托管服务。 它不会删除已收集并存储在群集的 Azure Monitor 工作区中的数据。

AKS 群集:

az aks update --disable-azure-monitor-metrics -n <cluster-name> -g <cluster-resource-group>

已启用 Azure Arc 的群集:

az k8s-extension delete --name azuremonitor-metrics --cluster-name <cluster-name> --resource-group <cluster-resource-group> --cluster-type connectedClusters 

该命令执行以下操作:

  • 从群集节点中删除 ama-metrics 代理。
  • 删除为该群集创建的记录规则。
  • 删除数据收集终结点 (DCE)。
  • 删除数据收集规则 (DCR)。
  • 删除在加入过程中创建的数据收集规则关联 (DCRA) 和记录规则组。

后续步骤

如果创建的工作区仅用于支持监视群集且不再被需要,则必须手动删除它。 如果不熟悉如何删除工作区,请参阅使用 Azure 门户删除 Azure Log Analytics 工作区。 不要忘记之前在步骤 4 中复制的“工作区资源 ID”。 你将需要该信息。