Container-Optimized OS には、一部のシステムログとコンテナログを Cloud Logging にエクスポートする Logging エージェントが含まれています。Container-Optimized OS 101 までは、x86 ベースの Container-Optimized OS イメージで、Fluentd をベースとするコンテナ化された Logging エージェントが使用されていました。Container-Optimized OS 105 では、代替の Logging エージェント実装である Fluent Bit の提供が開始されました。現行の Container-Optimized OS 109 では、Fluent Bit の Logging エージェントがデフォルトで使用されます。以前の Logging エージェント(Fluentd)は、Container-Optimized OS 113 から除外されます。
Arm ベースの Container-Optimized OS イメージのすべてのバージョンには Fluent Bit Logging エージェントが提供されます。
x86 ベースの Container-Optimized OS 105 イメージと Container-Optimized OS 109 イメージでは、それぞれ 2 種類の Logging エージェント実装(Fluentd(旧バージョンの場合)と Fluent Bit)を使用します。Container-Optimized OS 105 ではデフォルトで Fluentd を使用し、Container-Optimized OS 109 ではデフォルトで Fluent Bit を使用します。google-logging-use-fluentbit のメタデータ エントリを使用するとデフォルトの動作を変更できます。
Container-Optimized OS 105 で Fluent bit Logging エージェントを使用するには、google-logging-use-fluentbit の値を true に設定します。
Container-Optimized OS 109 で Fluentd Logging エージェントを使用するには、google-logging-use-fluentbit の値を false に設定します。
このロギング エージェントは、デフォルトで特定のシステム クリティカル サービスやユーザー アプリケーション コンテナから Cloud Logging バックエンドにログを送信するよう構成されています。たとえば、Docker コンテナのログ、選択した systemd サービス、監査ログ、ジャーナル ログエラーなどです。デフォルトの完全なロギング構成については、Container-Optimized OS 固有の構成ソース(x86 イメージと Arm イメージ)をご覧ください。
Container-Optimized OS 105 以前の x86 イメージの場合、ロギング エージェントは Google Cloud Observability の以前のコンテナ化 Logging エージェントです。ロギング エージェントを起動する Docker コマンドは、Container-Optimized OS ソースの stackdriver-logging.service で定義されています。実行されるコンテナ化されたエージェントのバージョンは、Container-Optimized OS ソースの app-admin/stackdriver ディレクトリに定義されています。
すべてのバージョンの ARM イメージと Container-Optimized OS 109 以降の x86 イメージの場合、Logging エージェントは Fluent Bit という組み込みの OS パッケージになります。エージェントは OS に組み込まれ、OS イメージとともに更新されます。
回避手段は、gcplogs を Docker ロギング ドライバとして使用せず、Container-Optimized OS で構成されたデフォルトのドライバを使用することです。Container-Optimized OS に含まれている Logging エージェントはコンテナログを Cloud Logging にエクスポートするため、両方のソリューションを同時に使用する必要はないことに留意してください。
Logging エージェント構成の互換性
Logging エージェントは x86 ベースの Container-Optimized OS イメージでは Fluentd ベースのコンテナとなり、Arm ベースの Container-Optimized OS イメージでは Fluent Bit バイナリとなります。2 つのエージェントの構成に互換性はありません。OS イメージに組み込まれているデフォルトのロギング構成のみを使用している場合、これは問題になりません。ただし、カスタム ロギング構成を使用している場合は、異なるアーキテクチャ ベースのイメージや、新しいバージョンの Container-Optimized OS にワークロードを移行する際に、中断が発生する可能性があります。
リファレンス
Google Cloud Observability の以前の Logging エージェントのドキュメント。Container-Optimized OS に含まれるコンテナ化された Logging エージェントは従来の Logging エージェントのサブセットであるため、このドキュメントでは Container-Optimized OS の範囲外にエージェントに関する一般的なコンテキストを説明しています。
Google Cloud Observability のドキュメント。Google Cloud Observability のドキュメントのホームページ。コンテキストとして便利です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-04-21 UTC。"],[[["\u003cp\u003eContainer-Optimized OS uses a logging agent to export system and container logs to Cloud Logging, with fluent-bit being the default agent as of version 109.\u003c/p\u003e\n"],["\u003cp\u003eThe logging agent is disabled by default, but can be enabled during instance creation or by updating an existing instance, using the \u003ccode\u003egoogle-logging-enabled\u003c/code\u003e metadata key.\u003c/p\u003e\n"],["\u003cp\u003eTo use the logging agent outside of Google Kubernetes Engine, you must have the \u003ccode\u003eroles/logging.viewer\u003c/code\u003e role to view logs and grant applications the \u003ccode\u003eroles/logging.logWriter\u003c/code\u003e role to write logs.\u003c/p\u003e\n"],["\u003cp\u003ex86-based Container-Optimized OS versions 105 and 109 offer a choice between the fluentd and fluent-bit logging agents, controllable via the \u003ccode\u003egoogle-logging-use-fluentbit\u003c/code\u003e metadata entry.\u003c/p\u003e\n"],["\u003cp\u003eStarting with milestone 89, avoid using the Docker \u003ccode\u003egcplogs\u003c/code\u003e logging driver with the included logging agent to prevent excessive warning logs and increased Cloud Logging charges, as the built-in agent already handles container log exporting.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Logging with Container-Optimized OS\n\nContainer-Optimized OS includes a logging agent which exports some\nsystem and container logs to Cloud Logging. Up until\nContainer-Optimized OS 101, x86-based Container-Optimized OS images used\na containerized logging agent based on fluentd. Container-Optimized OS 105\nstarted shipping an alternative logging agent implementation, fluent-bit.\nAs of Container-Optimized OS 109, the fluent-bit logging agent is the default.\nThe legacy logging agent, fluentd, will be removed in\nContainer-Optimized OS 113.\n\nAll versions of Arm-based Container-Optimized OS images ship the fluent-bit\nlogging agent.\n| **Note:** Logging is automatically available when you choose Container-Optimized OS as the node image for running your Google Kubernetes Engine clusters. These instructions are for when you are using Container-Optimized OS outside of GKE, such as in Compute Engine.\n\nEnable the logging agent\n------------------------\n\nThe logging agent is disabled by default. You can enable this feature when\ncreating a new instance or by updating an existing instance.\n\n### Access Requirements\n\nCloud Logging provides IAM\n[roles](/logging/docs/access-control#permissions_and_roles)\nthat you can use to grant appropriate access. In order to view your logs in a project,\nyou must have the `roles/logging.viewer` role and applications must have permission\nto write logs. You can grant this permission by assigning the\nIAM role `roles/logging.logWriter` to the service account for an\napplication.\n\nFor more information about permissions and roles, see\n[Predefined roles](/logging/docs/access-control#permissions_and_roles).\n\n### Create an instance with a logging agent enabled\n\n### Console\n\nTo run a Compute Engine instance on Container-Optimized OS with the fluent-bit logging\nagent enabled, perform the following:\n\n1. Open the Compute Engine instance creation page on Google Cloud console.\n\n [Create a new Compute Engine instance](https://console.cloud.google.com/compute/instancesAdd)\n2. Specify a **Name** for your instance.\n\n3. In the **Boot disk** section, select a Container-Optimized OS image.\n\n4. Click on **Management, security, disks, networking, sole tenancy** to\n expand additional options.\n\n5. Under the **Management** tab, scroll to the **Metadata** section. Add a\n new metadata entry, with **Key** as `google-logging-enabled` and **Value**\n as `true`.\n\n6. Optionally, specify any other options for your use case. See\n [Creating and configuring instances](/container-optimized-os/docs/how-to/create-configure-instance)\n for more details.\n\n7. Click **Create** to create and boot the instance.\n\n### gcloud\n\nTo run a Compute Engine instance on Container-Optimized OS with the logging\nagent enabled, use the `gcloud compute instances create` command, and include\n`google-logging-enabled=true` in the metadata. For example: \n\n```\ngcloud compute instances create instance-name \\\n --image image-name \\\n --image-project cos-cloud \\\n --zone compute-zone \\\n --metadata google-logging-enabled=true\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003einstance-name\u003c/var\u003e: the name of your VM instance.\n- \u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e: the name of the Container-Optimized OS image for the instance. For example, `--image=cos-113-18244-85-29`.\n- \u003cvar translate=\"no\"\u003ecompute-zone\u003c/var\u003e: the [compute zone](/compute/docs/regions-zones#available) for your instance.\n\nFor more information on the `gcloud` command, see the\n[gcloud compute instances create](/sdk/gcloud/reference/compute/instances/create)\nreference documentation.\nFor more details on creating Container-Optimized OS instances, see\n[Creating and configuring instances](/container-optimized-os/docs/how-to/create-configure-instance).\n\n### Selecting the logging agent\n\nx86-based Container-Optimized OS 105 and 109 images ship two implementations\nof the logging agent: fluentd (legacy) and fluent-bit.\nContainer-Optimized OS 105 uses fluentd by default and\nContainer-Optimized OS 109 uses fluent-bit by default. You can use the `google-logging-use-fluentbit`\nmetadata entry to change the default behavior.\n\nTo use fluent-bit logging agent on Container-Optimized OS 105 set\n`google-logging-use-fluentbit` value to `true`.\n\nTo use fluentd logging agent on Container-Optimized OS 109 set\n`google-logging-use-fluentbit` value to `false`.\n\n### Enable the logging agent in project metadata\n\nStarting in [milestone 97](/container-optimized-os/docs/release-notes/m97),\nlogging can be enabled in project metadata: \n\n gcloud compute project-info add-metadata \\\n --metadata google-logging-enabled=true\n\n| **Note:** Metadata flags defined at instance level takes precedence over metadata flags defined at project level.\n\nAccess logs\n-----------\n\n### Console\n\n1. Go to the VM instances page.\n\n [Go to the VM instances page](https://console.cloud.google.com/compute/instances)\n2. Click on the name of the Container-Optimized OS instance you want to access\n logs from.\n\n3. Under the **Logs** section, click Cloud Logging.\n\n4. This opens the Logs Explorer for the given instance. For more information,\n see [Using the Logs Explorer](/logging/docs/view/logs-explorer-interface).\n\n| **Note:** In the query builder, you can filter by log name. Click on **Log name** , and select the given log name. For example, **cos_audit** for Audit logs or **cos_containers** for docker container logs.\n\n### gcloud\n\nTo access logs, use the `gcloud logging read` command. For example: \n\n```\ngcloud logging read \\\n\"resource.type=gce_instance AND resource.labels.instance_id=instance-id\" \\\n --limit 10 \\\n --format json \\\n --freshness 30d\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003einstance-id\u003c/var\u003e: the id of your VM instance.\n\nThis command attempts to read logs from the VM instance with\n\u003cvar translate=\"no\"\u003einstance-id\u003c/var\u003e, limiting to 10 logs, in JSON format, from the last 30\ndays.\n\nFor more information on the `gcloud` command, see the\n[gcloud logging read](/sdk/gcloud/reference/logging/read) reference\ndocumentation.\n\nHow does it work?\n-----------------\n\nThe logging agent is configured by default to send logs from certain system\ncritical services and user application containers to the Cloud Logging\nbackend. For example, logs from docker containers, selected systemd services,\naudit logs, journal log errors, etc. See Container-Optimized OS specific\nconfiguration source ([x86 images](https://cos.googlesource.com/cos/overlays/board-overlays/+/refs/heads/main-R105/project-lakitu/app-admin/stackdriver/files/logging_configs/fluentd-lakitu.conf) and [Arm images](https://cos.googlesource.com/cos/overlays/board-overlays/+/refs/heads/main-R105/project-lakitu/app-admin/fluent-bit/files/fluent-bit.conf))\nfor complete default logging configuration.\n\nFor x86 images of Container-Optimized OS 105 and older, the logging agent is\nGoogle Cloud Observability's containerized legacy Logging agent. The docker command that\nstarts the logging agent is defined in the Container-Optimized OS\n[source for stackdriver-logging systemd service](https://cos.googlesource.com/cos/overlays/board-overlays/+/refs/heads/main-R105/project-lakitu/app-admin/stackdriver/files/stackdriver-logging.service).\nThe version of the containerized agent being run is defined in the Container-Optimized OS\n[source app-admin/stackdriver directory](https://cos.googlesource.com/cos/overlays/board-overlays/+/refs/heads/main-R105/project-lakitu/app-admin/stackdriver/files/env_vars).\n\nFor Arm images of all versions and x86 images for Container-Optimized OS 109 and\nlater, the logging agent is a built-in OS package called\n[fluent-bit](https://cos.googlesource.com/cos/overlays/board-overlays/+/refs/heads/master/project-lakitu/app-admin/fluent-bit).\nThe agent is built into the OS and updated along with the OS images.\n\nKnown Limitations\n-----------------\n\n### Compatibility with `gcplogs` driver\n\nStarting with\n[milestone 89](/container-optimized-os/docs/release-notes#release_schedule),\nif the logging agent included with Container-Optimized OS is enabled and Docker\n`gcplogs` logging driver is enabled for one or more containers, excessive\nwarning logs may be output by the included logging agent. This may create log\nnoise and/or increase Cloud Logging related charges.\n\nA workaround is to not use `gcplogs` as a Docker logging driver, and to\ninstead use the default driver as configured by Container-Optimized OS. Note\nthat the logging agent included with Container-Optimized OS will export\ncontainer logs to Cloud Logging, so using both solutions simultaneously is\nnot necessary.\n\n### Logging agent configuration compatibility\n\nThe logging agent is a fluentd-based container on x86-based\nContainer-Optimized OS images and a fluent-bit binary on Arm-based\nContainer-Optimized OS images. The configurations of the two agents are not\ncompatible. This is not a problem if you only rely on the default logging\nconfiguration built into the OS images. However, if you have a\ncustom logging configuration, you might experience breakage when migrating\nworkloads to images that are based on a different architecture or to a\nnewer version of Container-Optimized OS.\n\nReferences\n----------\n\n- Google Cloud Observability's legacy Logging agent [documentation](/logging/docs/agent/logging). The containerized logging agent included with Container-Optimized OS is a subset of the legacy Logging agent, so this documentation may provide context on the agent more generally, outside of the scope of Container-Optimized OS.\n- Google Cloud Observability [documentation](/products/operations). Homepage for Google Cloud Observability documentation; may be useful for context."]]