Send Container-Optimized OS service log output to Stackdriver Logging

1.7k views Asked by At

How do I get the output from my Cloud-Config service to Stackdriver Logging?

I am creating my VM instance using the node.js API, and have followed the example found here to create my service: https://cloud.google.com/container-optimized-os/docs/how-to/run-container-instance#starting_a_docker_container_via_cloud-config

Everything runs successfully, but the only way I can see the log output is by SSHing into the instance and running sudo journalctl -ef, but I would really like to stream the logs into Stackdriver Logging. But COS doesn't seem to allow me to install the logging agent.

Here is my service file, the /home/ci/run.sh just runs some docker containers which run some tests and output to stdout:

- path: /etc/systemd/system/ciservice.service
  permissions: 0644
  owner: root
  content: |
    [Unit]
    Description=Run tests
    Wants=gcr-online.target
    After=gcr-online.target

    [Service]
    User=ci
    Group=ci
    Environment="HOME=/home/ci"
    ExecStartPre=/usr/bin/docker-credential-gcr configure-docker
    ExecStart=/bin/bash /home/ci/run.sh

I'm using the Container-Optimized OS because it comes with Docker, GCR access out-of-the-box, security, and is quick to spin up. But I think I may have to switch back to an Ubuntu/Debian based image as that would allow me to install the logging agent, at the cost of more base configuration in a custom image.

Any help to use COS for this would be greatly appreciated, so thank you in advance :)

1

There are 1 answers

0
Naganuma Tatsumi On

Google Cloud Logging driver for Docker is available for this case. Here is a very good tutorial.

Although the logging driver has limited features for logging configuration. You need to control many logging configurations, I think the logging agent on Ubuntu/Debian is better choice.