容器见解默认为托管标识身份验证,该身份验证使用群集的托管标识将数据发送到Azure Monitor。 托管标识身份验证取代了旧版基于证书的本地身份验证,并且不再需要向群集添加 Monitoring Metrics Publisher 角色。
重要
容器见解的旧式身份验证已停用。 迁移到托管身份认证。 2026 年 9 月 30 日之后,不支持仍在使用旧式身份验证的群集,除非迁移到托管标识身份验证,否则不支持使用旧身份验证的群集。
本文介绍了如何在使用旧式身份验证方法启用容器见解后,迁移到托管标识身份验证。
如果群集使用旧式身份验证及其Log Analytics工作区密钥进行轮换,监视数据将停止流向Log Analytics工作区。 若要使用轮换后的工作区密钥恢复数据流,请先禁用容器见解加载项,然后再重新启用它。 若要避免此问题,请迁移到容器见解托管标识身份验证,该身份验证不使用Log Analytics工作区密钥。
先决条件
- 使用
az login登录 Azure CLI。 - Azure CLI 2.49.0 或更高版本。 若要检查版本,请运行
az version。 若要安装或更新Azure CLI,请参阅如何安装Azure CLI。 - 参与者 对群集的访问权限,可用于更新群集以及禁用或启用监控加载项。
使用旧式身份验证查找群集
以下查询会列出容器见解中使用旧版身份验证的群集。 若要运行查询,请使用 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
查询使用 Azure 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 公有云。
获取配置的 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工作区。
任何自定义监视配置将继续按预期运行。
现有警报、仪表板和操作工作流继续接收数据。
验证迁移
迁移群集后,再次运行适用的 Resource Graph 查询 。 迁移的群集不再出现在结果中,因为它现在使用托管标识身份验证。 在重新运行查询之前,允许群集配置更新几分钟。
后续步骤
如果升级代理时遇到问题,请查看故障排除指南来获得支持。