You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Kubernetes REST API获取多容器Pod的日志?

Kubernetes多容器Pod日志查询的正确API调用方式

当Pod包含多个容器时,Kubernetes REST API要求通过查询参数指定目标容器,而非修改URL路径结构,这就是你之前调用出错的原因。

正确调用格式

在原请求基础上,添加container查询参数指定容器名即可:

  • 查询nginx容器日志:
curl -k -H "Authorization: Bearer my-super-secret-token" https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log?container=nginx
  • 查询php-fpm容器日志:
curl -k -H "Authorization: Bearer my-super-secret-token" https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log?container=php-fpm

实用扩展参数

如果需要实时跟踪日志(对应kubectl logs -f的效果),可以追加follow=true参数:

curl -k -H "Authorization: Bearer my-super-secret-token" https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log?container=nginx&follow=true

内容的提问来源于stack exchange,提问作者Joel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 03:25:19