【问题标题】:Cloud Logging doesn't work on a Container-optimized OS running a containerCloud Logging 不适用于运行容器的容器优化操作系统
【发布时间】:2021-06-02 23:35:53
【问题描述】:

我正在容器优化操作系统下的 GCE 实例上运行 Docker 容器。我已遵循本手册 https://cloud.google.com/container-optimized-os/docs/how-to/logging 并添加了 google-logging-enabled 元数据值以启用将容器的日志发送到 Cloud Logging:

instance metadata screenshot

但它不起作用。我在 Cloud Logging 中看不到容器的日志:

cloud logging screenshot

虽然我在现实中有很多容器日志:

container logs screenshot

如何让它工作并真正将容器的日志发送到 Cloud Logging?

更新 日志过滤器是默认的:(resource.type="gce_instance" AND resource.labels.instance_id="***") OR (resource.type="global" AND jsonPayload.instance.id="***"),这意味着应该显示来自当前实例的所有类型的日志。

【问题讨论】:

  • 使用此过滤器 "resource.type="gce_instance" AND resource.labels.instance_id="xxxxxxxxx" AND logName=projects/xxxxxxxxxx/logs/cos_containers"
  • COS 设置了低日志记录级别。这意味着更高级别的日志不会发送到 Stackdriver。我对此进行了一些研究,但从未找到更改日志级别的永久解决方案。我认为只有 ERROR 和 WARN 会传递给 Stackdriver。我对这篇文章的回答有详细信息:stackoverflow.com/a/65768214/8016720
  • @John Hanley,Cloud Logging 和 Stackdriver 有什么关系?据我了解,它们是两种不同的服务?
  • Stackdriver 是 Operations: Cloud Logging 的旧名称。我仍然出于习惯使用术语 Stackdriver。我最喜欢的服务之一。

标签: docker google-cloud-platform google-compute-engine google-container-optimized-os


【解决方案1】:

我的问题是我与实例关联的服务帐户没有Logs Writer 权限。我通过运行sudo systemctl status stackdriver-logging 命令发现了这一点:

● stackdriver-logging.service - Fluentd container for Stackdriver Logging
   Loaded: loaded (/usr/lib/systemd/system/stackdriver-logging.service; static; vendor preset: disabled)
   Active: active (running) since Fri 2021-03-05 01:18:55 UTC; 1h 12min ago
 Main PID: 385 (docker)
    Tasks: 9 (limit: 2382)
   Memory: 31.9M
      CPU: 751ms
   CGroup: /system.slice/stackdriver-logging.service
           └─385 /usr/bin/docker run --rm --name=stackdriver-logging-agent -v /etc/stackdriver/logging.config.d/:/etc/google-fluentd/config.d/ -v /var/log:/var/log -v /var/lib/docker/containers/:/v

Mar 05 02:30:11 jwp-gitlab-runner-m3l0 docker[385]: 2021-03-05 02:30:11 +0000 [warn]: #0 Dropping 1 log message(s) error="User unauthorized to access *** for resource ***

通过谷歌搜索错误消息,我在 GitHub 问题 https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud/issues/295 中找到了答案

以下答案也帮助我诊断了问题:https://stackoverflow.com/a/65768214/8016720

现在我在 Cloud Logging 中拥有了我想要的所有日志。

【讨论】:

  • 我评论中的答案链接包括诊断此问题的步骤。
  • 是的,您还提到了这个角色名称。但我在阅读时不知何故错过了它......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-08
  • 2019-12-09
相关资源
最近更新 更多