如何管理用于容器的 Azure Monitor 代理How to manage the Azure Monitor for containers agent

用于容器的 Azure Monitor 使用适用于 Linux 的 Log Analytics 代理的容器化版本。Azure Monitor for containers uses a containerized version of the Log Analytics agent for Linux. 初始部署之后,在其生命周期内可能需要执行一些例程或可选任务。After initial deployment, there are routine or optional tasks you may need to perform during its lifecycle. 本文详细介绍如何手动升级代理并禁用来自特定容器的环境变量集合。This article details on how to manually upgrade the agent and disable collection of environmental variables from a particular container.

如何升级用于容器的 Azure Monitor 代理How to upgrade the Azure Monitor for containers agent

用于容器的 Azure Monitor 使用适用于 Linux 的 Log Analytics 代理的容器化版本。Azure Monitor for containers uses a containerized version of the Log Analytics agent for Linux. 发布该代理的新版本时,在 Azure Kubernetes 服务 (AKS) 和 Azure Red Hat OpenShift 版本 3.x 上承载的托管 Kubernetes 群集上,该代理会自动升级。When a new version of the agent is released, the agent is automatically upgraded on your managed Kubernetes clusters hosted on Azure Kubernetes Service (AKS) and Azure Red Hat OpenShift version 3.x. 对于混合 Kubernetes 群集和 Azure Red Hat OpenShift 版本 4.x,未托管该代理,需要手动升级该代理。For a hybrid Kubernetes cluster and Azure Red Hat OpenShift version 4.x, the agent is not managed, and you need to manually upgrade the agent.

如果 AKS 上托管的群集的代理升级失败,也可参阅本文,了解如何手动升级代理。If the agent upgrade fails for a cluster hosted on AKS, this article also describes the process to manually upgrade the agent. 要关注发布的版本,请参阅代理发布公告To follow the versions released, see agent release announcements.

升级 AKS 群集上的代理Upgrade agent on AKS cluster

升级 AKS 群集上的代理的过程包括两个明确的步骤。The process to upgrade the agent on AKS clusters consists of two straight forward steps. 第一个步骤是使用 Azure CLI 禁止通过用于容器的 Azure Monitor 进行监视。The first step is to disable monitoring with Azure Monitor for containers using Azure CLI. 请遵循禁用监视一文中介绍的步骤。Follow the steps described in the Disable monitoring article. 可以使用 Azure CLI 从群集的节点中删除代理,不会影响解决方案以及工作区中存储的相应数据。Using Azure CLI allows us to remove the agent from the nodes in the cluster without impacting the solution and the corresponding data that is stored in the workspace.

备注

执行此维护活动时,群集中的节点不会转发所收集的数据,并且性能视图不会显示从删除代理到安装新版本这段时间内的数据。While you are performing this maintenance activity, the nodes in the cluster are not forwarding collected data, and performance views will not show data between the time you remove the agent and install the new version.

若要安装代理的新版本,请遵循使用 Azure CLI 启用监视中介绍的步骤来完成此过程。To install the new version of the agent, follow the steps described in the enable monitoring using Azure CLI, to complete this process.

重新启用监视后,可能需要约 15 分钟才能查看群集的更新后运行状况指标。After you've re-enabled monitoring, it might take about 15 minutes before you can view updated health metrics for the cluster. 若要验证代理是否已成功升级,可以执行以下操作:To verify the agent upgraded successfully, you can either:

  • 运行 kubectl get pod <omsagent-pod-name> -n kube-system -o=jsonpath='{.spec.containers[0].image}' 命令。Run the command: kubectl get pod <omsagent-pod-name> -n kube-system -o=jsonpath='{.spec.containers[0].image}'. 在返回的状态中,记下输出的“容器”部分中“映像”下 omsagent 的值。In the status returned, note the value under Image for omsagent in the Containers section of the output.
  • 在“节点”选项卡上选择群集节点,然后在右侧的“属性”窗格中记下“代理映像标记”下的值。 On the Nodes tab, select the cluster node and on the Properties pane to the right, note the value under Agent Image Tag.

显示的代理版本应与版本历史记录页上列出的最新版本匹配。The version of the agent shown should match the latest version listed on the Release history page.

升级混合 Kubernetes 群集上的代理Upgrade agent on hybrid Kubernetes cluster

执行以下步骤,升级在以下位置运行的 Kubernetes 群集上的代理:Perform the following steps to upgrade the agent on a Kubernetes cluster running on:

  • Azure 上托管的使用 AKS 引擎的自管理 Kubernetes 群集。Self-managed Kubernetes clusters hosted on Azure using AKS Engine.
  • Azure Stack 上或在本地托管的使用 AKS 引擎的自管理 Kubernetes 群集。Self-managed Kubernetes clusters hosted on Azure Stack or on-premises using AKS Engine.

运行以下命令:Run the following command:

$ helm upgrade --name myrelease-1 \
--set omsagent.domain=opinsights.azure.cn,omsagent.secret.wsid=<your_workspace_id>,omsagent.secret.key=<your_workspace_key>,omsagent.env.clusterName=<your_cluster_name> incubator/azuremonitor-containers

如何禁用容器上的环境变量集合How to disable environment variable collection on a container

用于容器的 Azure Monitor 从在 pod 中运行的容器中收集环境变量,并将这些环境变量显示在“容器”视图中所选容器的属性窗格中。Azure Monitor for containers collects environmental variables from the containers running in a pod and presents them in the property pane of the selected container in the Containers view. 可在部署 Kubernetes 集群期间或之后通过设置环境变量 AZMON_COLLECT_ENV 禁用特定容器的集合来控制此行为。You can control this behavior by disabling collection for a specific container either during deployment of the Kubernetes cluster, or after by setting the environment variable AZMON_COLLECT_ENV. 此功能可从代理版本 ciprod11292018 或更高版本获得。This feature is available from the agent version - ciprod11292018 and higher.

要禁用新容器或现有容器上的环境变量集合,请在 Kubernetes 部署 yaml 配置文件中将变量 AZMON_COLLECT_ENV 设置为“False”值 。To disable collection of environmental variables on a new or existing container, set the variable AZMON_COLLECT_ENV with a value of False in your Kubernetes deployment yaml configuration file.

- name: AZMON_COLLECT_ENV  
  value: "False"  

运行以下命令,将更改应用到 Kubernetes 群集:kubectl apply -f <path to yaml file>Run the following command to apply the change to Kubernetes clusters): kubectl apply -f <path to yaml file>. 要验证配置更改是否生效,请在用于容器的 Azure Monitor 中的“容器”视图中选择容器,并在属性面板中展开“环境变量” 。To verify the configuration change took effect, select a container in the Containers view in Azure Monitor for containers, and in the property panel, expand Environment Variables. 此部分应只显示前面创建的变量 - AZMON_COLLECT_ENV=FALSE。The section should show only the variable created earlier - AZMON_COLLECT_ENV=FALSE. 对于所有其他容器,环境变量部分应列出发现的所有环境变量。For all other containers, the Environment Variables section should list all the environment variables discovered.

要重新启用环境变量的发现,请应用与前面相同的过程,将值从“False”更改为“True”,然后重新运行 kubectl 命令来更新容器 。To re-enable discovery of the environmental variables, apply the same process earlier and change the value from False to True, and then rerun the kubectl command to update the container.

- name: AZMON_COLLECT_ENV  
  value: "True"  

后续步骤Next steps

如果升级代理时遇到问题,请查看故障排除指南来获得支持。If you experience issues while upgrading the agent, review the troubleshooting guide for support.