在 Azure Kubernetes Fleet Manager 中查看代理日志

本文介绍如何在 Azure Kubernetes Fleet Manager 中查看中心群集和成员群集中的 Fleet 代理日志。 如果您的机队启用了中心群集模式,Azure Kubernetes Fleet Manager 会在中心群集和成员群集中安装 Fleet 代理,以促进整个机队的通信并协调操作,从而支持机队的工作负载编排和负载均衡功能。 这些代理生成日志,以便深入了解:

  • 代理运行状况和连接状态
  • 工作负荷编排配置更改和操作更新
  • 负载均衡配置更改和操作更新

可以检索这些日志以进行监视、故障排除和/或审核。

在相关资源上配置诊断设置

机队代理日志作为 Azure Monitor 中的 资源日志 实现,具体来说:

  • 机队中心集群的机队代理日志作为机队资源日志的一部分被实现。
    • 两个代理安装在机队中心群集上,通常称为“舰队中心代理”,其中包括:
      • fleet-hub-agent:在中心群集端管理群集成员身份和处理工作负载业务流程任务(例如,计划、推出更改)的舰队代理。
      • fleet-hub-net-controller-manager:在中心群集端处理负载均衡任务的舰队代理。
  • 机队成员群集的机队代理日志作为 AKS 群集资源资源日志的一部分实现。
    • 三个代理安装在机队成员群集上,通常称为机队成员代理,其中包括:
      • fleet-member-agent:将成员群集注册到中心群集并在成员群集端处理工作负载业务流程任务(例如,应用清单、偏移检测、接管)的舰队代理。
      • fleet-member-net-controller-manager:处理成员群集端上的负载均衡任务的机队代理。
      • fleet-mcs-controller-manager:用于促进多群集服务的舰队代理。

在创建诊断设置以将其路由到一个或多个位置之前,不会收集和存储资源日志。 Azure Monitor 支持可以使用的各种位置,例如 Azure 存储帐户或 Log Analytics 工作区;有关可用位置及其限制的列表,请参阅 Azure Monitor 诊断设置目标 页。

若要收集 Fleet 代理日志,请为相应的资源创建诊断设置。 根据机队用例,可以选择仅从一个或多个特定机队代理收集日志。 最简单的方法是使用 Azure 门户;请参阅有关进一步说明的步骤。 还可以使用 Azure CLI、PowerShell、Azure 资源管理器、REST API 或 Azure Policy 来设置事项:有关详细信息,请参阅 “创建诊断设置”。

重要

收集机队代理日志时可能会产生大量成本。 建议进行如下操作:

在舰队资源上为舰队中心代理日志配置诊断设置

  1. 登录到 Azure 门户
  2. 在搜索框中,输入 Kubernetes Fleet Manager ,然后从搜索结果中选择 Kubernetes Fleet Manager
  3. 在所有机队资源列表中,找到您希望从中收集舰队枢纽代理日志的机队。 点击“舰队名称”。 可能需要调整筛选条件以找到所需的舰队资源。
  4. 在资源菜单上的“监视”下选择“诊断设置”。
  5. 选择“添加诊断设置”。
  6. 为诊断设置输入一个名称。
  7. 对于日志类别,请确保至少选择两个类别中的一个:fleet-hub-agentfleet-hub-net-controller-manager。 还可以根据需要选择其他日志类别。
  8. 对于目标详细信息,请选择你喜欢的目标。 将显示更多选项,要求你提供额外的目标信息。 有关详细信息,请参阅 “创建诊断设置”。
  9. 选择“保存”

片刻之后,新设置将显示在此资源的诊断设置列表中。 日志在生成新数据时流式传输到指定的目标。 从代理发出日志到日志出现在所选目标中,可能需要一段时间。

在成员 AKS 群集资源上为舰队成员代理日志配置诊断设置

  1. 登录到 Azure 门户
  2. 在搜索框中,输入 Kubernetes 服务 ,然后从搜索结果中选择 Kubernetes 服务
  3. 在所有 AKS 群集资源列表中,找到已作为成员群集加入舰队并且你希望从中收集舰队成员代理日志的 AKS 群集。 单击 AKS 群集名称。 可能需要调整筛选器条件才能找到所需的 AKS 群集资源。
  4. 在资源菜单上的“监视”下选择“诊断设置”。
  5. 选择“添加诊断设置”。
  6. 为诊断设置输入一个名称。
  7. 对于日志类别,请确保至少选择了三个类别中的一个、fleet-member-agentfleet-member-net-controller-managerfleet-mcs-controller-manager。 还可以根据需要选择其他日志类别。
  8. 对于目标详细信息,请选择你喜欢的目标。 将显示更多选项,要求你获取更多目标信息。 有关详细信息,请参阅 “创建诊断设置”。 如果计划将 Log Analytics 工作区用作目标,AKS 群集资源支持 Azure 诊断模式和资源特定的模式。 有关这两种模式之间的差异,请参阅 “发送到 Log Analytics 工作区 ”页上的说明。
  9. 选择“保存”

片刻之后,新设置将显示在此资源的诊断设置列表中。 日志在生成新数据时流式传输到指定的目标。 从代理发出日志到它出现在您选择的目标地点之间,可能需要花费一段时间。

查看机队代理日志

若要查看所选目标中的 Fleet 代理日志,请参阅 将 Azure 资源日志发送到 Log Analytics 工作区、事件中心或 Azure 存储

注释

如果使用 Log Analytics 工作区作为目标:

  • 使用 Azure 诊断模式时,可以在 AzureDiagnostics 表中找到机队成员代理日志。
  • 在资源特定模式下,可以在 AKSControlPlane 表中找到舰队成员代理日志。

了解舰队代理日志

机队代理日志以非结构化格式klog写入;其格式为

[IWEF]yyyymmdd hh:mm:ss.uuuuuu threadid file:line msg kvs

地点:

  • [IWEF] 是日志级别。
    • I 表示 info 级别。
    • W 表示 warning 级别。
    • E 表示 error 级别。
    • F 表示 fatal 级别。
  • yyyymmdd是发出日志的年份(yyyy)、月份(mm)和日期(dd)。
  • hh:mm:ss.uuuuuu 是发出日志时的时间戳(hh 小时、 mm 分钟、 ss 秒和 uuuuuu 微秒)。
  • threadid 是舰队代理进程/线程的线程 ID (PID/TID)。
  • file:line 是发出日志的源代码的文件名和行号。
  • msg 是日志消息。
  • kvs 是一个键值对的列表(例如 work=123),它提供其他信息,例如日志消息所涉及的 API 对象。

你可能希望使用 Fleet 代理源代码交叉引用日志消息,以便更好地了解上下文中的日志消息。 有关 Fleet 代理fleet-hub-agentfleet-member-agent,请参阅KubeFleet GitHub 存储库; 有关fleet-hub-net-controller-managerfleet-member-net-controller-managerfleet-mcs-controller-manager,请参阅 Azure Fleet Networking GitHub 存储库

有用的 Kusto 查询

以下 Kusto 查询列表有助于更轻松地在 Log Analytics 工作区中搜索 Fleet 代理日志:

注释

这些示例假定在收集机队成员代理日志时使用 Azure 诊断模式。 如果已启用特定于资源的模式,请改用 AKSControlPlane 表作为适用的查询示例。

  • 从所有车队中心代理检索最新的 1,000 条日志记录。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category in ("fleet-hub-agent", "fleet-hub-net-controller-manager")
| order by TimeGenerated desc
| take 1000
  • 从所有舰队成员代理检索最新的 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category in ("fleet-member-agent", "fleet-member-net-controller-manager", "fleet-mcs-controller-manager")
| order by TimeGenerated desc
| take 1000
  • 检索有关 Fleet 如何在中心群集端管理群集成员身份的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "v1beta1/member_controller.go"
| order by TimeGenerated desc
| take 1000
  • 检索有关 Fleet 如何处理 ClusterResourcePlacement API 对象的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "clusterresourceplacement/"
| order by TimeGenerated desc
| take 1000
  • 检索有关机队计划工作负荷的方式的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "scheduler/" or log_s contains "framework/"
| order by TimeGenerated desc
| take 1000
  • 检索有关 Fleet 如何处理滚动更新的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "rollout/"
| order by TimeGenerated desc
| take 1000
  • 检索有关机队处理暂存更新的方式的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "updaterun/"
| order by TimeGenerated desc
| take 1000
  • 检索有关 Fleet 如何将工作负荷同步到成员群集的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-agent"
| where log_s contains "workgenerator/"
| order by TimeGenerated desc
| take 1000
  • 检索有关舰队如何在成员群集端报告群集成员身份的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-member-agent"
| where log_s contains "v1beta1/member_controller.go"
| order by TimeGenerated desc
| take 1000
  • 检索有关 Fleet 如何将清单应用于特定成员群集的最新 1,000 个日志条目。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-member-agent"
| where log_s contains "workapplier/"
| order by TimeGenerated desc
| take 1000
  • 检索最新的 1,000 个日志条目,了解 Fleet 如何在中心集群一侧管理网络能力的终端导出/导入。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-net-controller-manager"
| where log_s contains "endpointsliceexport/"
| order by TimeGenerated desc
| take 1000
  • 检索最新的 1,000 个日志条目,了解 Fleet 如何管理服务导出/导入,以便在中心群集端使用网络功能。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-net-controller-manager"
| where log_s contains "serviceimport/" or log_s contains "internalserviceimport/" or log_s contains "internalserviceexport/"
| order by TimeGenerated desc
| take 1000
  • 检索最新的 1,000 个日志条目,了解 Fleet 如何管理 Azure 流量管理器相关资源以用于网络功能。
// Replace YOUR-RESOURCE-ID with the value of your Fleet resource.
// To view the ID, go to the Fleet resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-hub-net-controller-manager"
| where log_s contains "trafficmanagerbackend/" or log_s contains "trafficmanagerprofile/"
| order by TimeGenerated desc
| take 1000
  • 获取有关 Fleet 如何在成员集群端管理网络功能的终端出口/进口的最新 1,000 条日志记录。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-member-net-controller-manager"
| where log_s contains "endpointslice/" or log_s contains "endpointsliceexport/" or log_s contains "endpointsliceimport/"
| order by TimeGenerated desc
| take 1000
  • 检索最新的 1,000 个日志条目,了解 Fleet 如何管理服务导出/导入,以便在成员群集端使用网络功能。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-member-net-controller-manager"
| where log_s contains "serviceexport/" or log_s contains "serviceimport/"
| order by TimeGenerated desc
| take 1000
  • 检索最新的 1,000 个日志条目,了解 Fleet 如何管理多群集服务以使用网络功能。
// Replace YOUR-RESOURCE-ID with the value of your AKS member cluster resource.
// To view the ID, go to the AKS cluster resource page, and select JSON view on the overview page.
AzureDiagnostics
| where _ResourceId == YOUR-RESOURCE-ID
| where Category == "fleet-mcs-controller-manager"
| where log_s contains "multiclusterservice/"
| order by TimeGenerated desc
| take 1000