容器见解默认使用托管标识身份验证,此身份验证提供一个监控代理,该代理使用集群的托管标识将数据发送到 Azure Monitor。 它取代了旧版基于证书的本地身份验证,并使得无需再将“监视指标发布者”角色添加到群集。
重要
容器见解的旧式身份验证已停用。 迁移到托管身份认证。 2026 年 9 月 30 日之后,不支持仍在使用旧式身份验证的群集,除非迁移到托管标识身份验证,否则不支持使用旧身份验证的群集。
本文介绍如何在使用旧式身份验证方法启用容器见解时迁移到托管标识身份验证,以及如何启用旧式身份验证(如果需要)。
重要
如果群集采用旧式身份验证且 Log Analytics 工作区密钥轮换,则监视数据将停止流向 Log Analytics 工作区。 必须禁用容器洞察扩展,然后重新启用,以便监控数据开始通过新的轮换工作区键再次流动。 应迁移到不使用 Log Analytics 工作区密钥的容器见解托管标识身份验证。
使用旧式身份验证查找群集
以下查询列出了容器见解中使用旧式身份验证的群集。 若要运行查询,请使用 Resource Graph 资源管理器。 查询在现有的 Azure 门户范围内运行。 有关如何在门户中设置范围和运行 Azure Resource Graph 查询的详细信息,请参阅 快速入门:使用 Azure 门户运行 Resource Graph 查询。
查询 AKS 群集
resources
| where type =~ 'Microsoft.ContainerService/managedClusters'
| project id, name, aksproperties = parse_json(tolower(properties)), location, identity
| extend isEnabled = aksproperties.addonprofiles.omsagent.enabled
| extend workspaceResourceId = iif(isEnabled == true, aksproperties.addonprofiles.omsagent.config.loganalyticsworkspaceresourceid, '')
| extend useAADAuth = aksproperties.addonprofiles.omsagent.config.useaadauth
| where isEnabled =~ "true" and useAADAuth != true
| extend parts = split(tostring(id), "/")
| extend subscriptionId = parts[2], AKSClusterName = parts[-1], resourceGroupName = parts[4]
| project AKSClusterName, resourceGroupName, subscriptionId, location, AKSClusterId = tolower(id), workspaceResourceId
查询本地部署群集,即指使用 Arc 的群集。
KubernetesConfigurationResources
| where type =~ "Microsoft.KubernetesConfiguration/extensions"
| extend properties = parse_json(tolower(properties))
| extend extensionType = properties.extensiontype
| where extensionType in~ ('microsoft.azuremonitor.containers')
| extend omsagentUseAADAuth = tostring(properties.configurationsettings.["omsagent.useaadauth"])
| extend amalogsUseAADAuth = tostring(properties.configurationsettings.["amalogs.useaadauth"])
| extend useAADAuth = iff(omsagentUseAADAuth == 'true' or amalogsUseAADAuth == 'true', 'true', 'false')
| extend workspaceResourceId = tostring(properties.configurationsettings.loganalyticsworkspaceresourceid)
| extend resourceId = tolower(split(id, "/providers/Microsoft.KubernetesConfiguration")[0])
| where useAADAuth != "true"
| extend parts = split(tostring(resourceId), "/")
| extend subscriptionId = parts[2], ClusterName = parts[-1], ResourceGroupName = parts[4]
| project ClusterName, ResourceGroupName,resourceId, subscriptionId, workspaceResourceId
迁移到托管身份认证
如果在托管标识身份验证可用之前启用了容器洞察,您可以使用以下方法来迁移群集。 托管标识身份验证更安全且性能更高。 它使你能够访问较新的 Azure Monitor Container Insights 功能,例如 syslog 集合和大规模日志模式。
AKS
AKS 群集必须首先禁用监视,然后升级到托管标识。 此次迁移目前仅支持 Azure 公有云、世纪互联运营的 Microsoft Azure 和 Azure 政府云。 对于具有用户分配的标识的群集,仅支持 Azure 公有云。
注意
最低 Azure CLI 2.49.0 或更高版本。
获取配置的 Log Analytics 工作区资源 ID:
az aks show -g <resource-group-name> -n <cluster-name> | grep -i "logAnalyticsWorkspaceResourceID"使用以下命令禁用监视:
az aks disable-addons -a monitoring -g <resource-group-name> -n <cluster-name>如果群集当前使用的是服务主体,请使用以下命令将服务主体升级为系统托管标识:
az aks update -g <resource-group-name> -n <cluster-name> --enable-managed-identity使用在步骤 1 中获取的 Log Analytics 工作区资源 ID 启用具有托管标识身份验证选项的监视加载项:
az aks enable-addons -a monitoring -g <resource-group-name> -n <cluster-name> --workspace-resource-id <workspace-resource-id>
支持 Arc 的 Kubernetes
检索为容器见解扩展配置的 Log Analytics 工作区。
az k8s-extension show --name azuremonitor-containers --cluster-name \<cluster-name\> --resource-group \<resource-group\> --cluster-type connectedClusters -n azuremonitor-containers使用第一步返回的工作区,通过托管标识身份验证选项启用容器洞察扩展。
az k8s-extension create --name azuremonitor-containers --cluster-name \<cluster-name\> --resource-group \<resource-group\> --cluster-type connectedClusters --extension-type Microsoft.AzureMonitor.Containers --configuration-settings amalogs.useAADAuth=true logAnalyticsWorkspaceResourceID=\<workspace-resource-id\>
迁移到托管标识身份验证时会发生什么情况?
迁移到托管标识身份验证时,Container Insights 会更改其使用 Azure Monitor 进行身份验证的方式。 此次迁移仅会更改 Container Insights 监控配置,不会更改您的应用程序、工作负载或 Kubernetes 资源。
保持不变的内容
你将保留现有的 Log Analytics 工作区和之前收集的监视数据。
容器见解在迁移后持续收集并发送监控数据。
只要迁移后数据仍能成功收集,使用 Container Insights 数据的现有仪表板、工作簿、警报和查询就将继续正常工作。
无需更改应用程序代码或工作负载。
有哪些变化
容器见解停止使用旧版身份验证,开始使用托管标识身份验证。
群集监视配置已更新为使用未来 Container Insights 功能和支持所需的受支持的身份验证模型。
迁移影响
在迁移期间,在更新监视配置时,数据收集可能会暂时中断。 迁移后,验证监视数据是否流向工作区,以及预期监视体验是否正常运行。
迁移后建议的验证
迁移后,请验证:
容器洞察成功上报运行状况和遥测数据。
新日志和指标将抵达Log Analytics工作区。
任何自定义监视配置将继续按预期运行。
现有警报、仪表板和操作工作流继续接收数据。
启用旧式身份验证
如果需要旧式身份验证,请参阅启用容器见解,其中包含用于启用容器见解的不同选项的示例。
后续步骤
如果升级代理时遇到问题,请查看故障排除指南来获得支持。