Tin*_*goi 19 tail kubernetes kubectl
kubectl logs -f pod显示从头开始的所有日志,当日志很大时它会成为问题,我们必须等待几分钟才能获得最后一个日志.从远程连接时,它变得更加糟糕.有没有办法可以为最后100行日志留下日志并跟踪它们?
Nic*_*Ben 36
在集群中,最佳实践是通过聚合器在单个点收集所有日志,并使用专用工具对其进行分析.因此在K8S中,log命令非常基本.
无论如何,kubectl logs -h显示一些对你有用的选项:
# Display only the most recent 20 lines of output in pod nginx
kubectl logs --tail=20 nginx
# Show all logs from pod nginx written in the last hour
kubectl logs --since=1h nginx
Run Code Online (Sandbox Code Playgroud)
github上提供了一些符合您要求(以及更多)的工具,其中一些工具包括:
Gol*_*tha 12
从具有多个容器的 Pod 日志中获取尾行。
kubectl logs <pod name> --all-containers=true --tail=10
Run Code Online (Sandbox Code Playgroud)
要从应用程序内的 Pod 日志中获取尾行:
kubectl logs --selector app=<your application> --tail=10
Run Code Online (Sandbox Code Playgroud)
(例如:如果您的应用程序有 3 个 pod,则上述命令的输出可以是 30 个日志,每个 pod 的 10 个日志)
您可以使用这种方式获取前 10 行
kubectl logs my-pod-name -n my-ns | head -n 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15198 次 |
| 最近记录: |