dvasdekis
dvasdekis

Reputation: 157

`gcloud compute instances create-with-container` not logging to stackdriver

I've got a container which logs normally through the standard Docker drivers. I've now run this container on GCP via the gcloud compute instances create-with-container command, and I want to see the logs in Stackdriver. Right now, they do not appear.

From what I can tell, combining the advice from here and here, I have to start the host instance, set the default logging driver to GCP by editing docker's daemon.json, and then restart the host instance.

Is this truly the easiest way to get these containers to log to the normal standard google cloud logging solution? I think that gcloud compute instances create-with-container should do this by default, and that I'm missing something.

Upvotes: 3

Views: 1386

Answers (3)

Milan Cermak
Milan Cermak

Reputation: 8064

For me, the issue was about permissions. Classic.

I used the --service-account parameter to create the container with a custom service account, but it did not have the Logging Write and Monitoring Write permissions. I though using --scopes=default would be enough, but no.

FWIW, I'm using a f1-micro to run a small node.js background app (no HTTP server) and the logging works without a problem.

For whoever visits this in the future, have a look at this checklist to verify your setup.

Upvotes: 2

Serhii
Serhii

Reputation: 4461

Your VM runs at Compute Engine, so it doesn't contain Stackdriver logging service as it included by default only in "VMs are running in Google Kubernetes Engine or App Engine".

I completely agree with @JohnHanley. You have to install Stackdriver Logging service on your instance manually accordingly to the guideline here. At first, I'd recommend you to check supported VM list just to be sure that logging service will run at your instance properly and then follow the rest of the instructions. In case you have any troubles after installing logging services follow the troubleshooting. Please provide additional information about your steps if you won't solve the problem in this way.

UPDATE to clarify my answer. By default Stackdriver is able to collect only limited logs from the instance (list). So, in case you want to get more logs from you VM additional configuration will be required.

Upvotes: 1

dvasdekis
dvasdekis

Reputation: 157

Okay, turns out the Stackdriver logger does work nicely by default when using gcloud compute instances create-with-container, so your logs should appear automatically.

They didn't for me because it seems that an f1-micro instance doesn't have the grunt to spin up a container that does even a small amount of work on top of the Docker overhead - switching to a g1-small fixed this.

Upvotes: 2

Related Questions