有没有专门做特产的网站,最新新闻热点头条,智慧团建登录手机版入口,四川省建设监理协会官方网站背景需求
Azure#xff08;Global#xff09; AKS集群中#xff0c;需要查询部署服务的历史日志#xff0c;例如#xff1a;我部署了服务A#xff0c;但服务A的上一个版本Pod已经被杀掉由于版本的更新迭代#xff0c;而我在命令行中只能看到当前版本的pod日志#xff…背景需求
AzureGlobal AKS集群中需要查询部署服务的历史日志例如我部署了服务A但服务A的上一个版本Pod已经被杀掉由于版本的更新迭代而我在命令行中只能看到当前版本的pod日志无法通过kubectl logs 看到应用的历史日志例如上一个版本的pod日志但如果这时候需要看那么就需要手动去写AKS的KQL语句来查询了
查询语句Azure Global
##queryPodLogs for Azure Global AKS
let startTimestamp ago(7d);
//namespace
let aksNameSpace shop;
// specific podName
let aksPodName shop-backend-dev-j9w;
// specific contaierName
let aksContainerName shop-backend-dev;
// queryStartTime(UTC)
// queryEndTime(UTC)
ContainerLogV2
| where TimeGenerated startTimestamp
| where PodName contains aksPodName and PodNamespace contains aksNameSpace and ContainerName contains aksContainerName
| where TimeGenerated between(datetime(2024-04-27 00:00:00) .. datetime(2024-04-30 05:00:00))
| project TimeGenerated, PodNamespace, ContainerId, ContainerName, PodName, LogMessage, LogSource
| sort by TimeGenerated desc
查询注意事项
查询前记得修改下图上红线所划出来的参数值具体解释都有标注
Tips
如果不行的话试下我在下面提供的另一条KQL语句因为在我写KQL语句的这段时间似乎Azure Monitor这个模块的数据表正在做迁移最后我是试了上面的语句成功查询出来的而Azure内部的朋友经过实验他是用以下语句联表查询到的数据但我用下面这个语句查出来就一直是空的查不到任何数据所以这个可能需要视情况而定。
let startTimestamp ago(7d);
let aksNameSpace shop;
let aksPodName shop-backend-dev-j9w;
// let aksContainerName shop-backend-dev;
KubePodInventory
| where TimeGenerated startTimestamp
| project ContainerID, PodNameName, Namespace, ContainerName
| where PodName contains aksPodName and Namespace contains aksNameSpace
// and ContainerName contains aksContainerName
| distinct ContainerID, PodName, ContainerName
| join
(ContainerLogV2| where TimeGenerated between(datetime(2024-04-29 00:00:00) .. datetime(2024-04-29 05:00:00)) //修改时间
)
on ContainerName
| project TimeGenerated, PodName, ContainerName, LogMessage, LogSource
| sort by TimeGenerated desc