Stackdriver - How to fetch logs of a kubernetes pod running on Google Cloud using REST APIs?

8/30/2018

My application is deployed on a Kubernetes Cluster that runs on Google Cloud. I want to fetch logs written by my application using Stackdriver's REST APIs for logging.

From the above documentation page and this example, it seems that I can only list logs of a project, organization, billing account or folder.

I want to know if there are any REST APIs using which I can fetch logs of:

  • A pod in a Kubernetes Cluster running on Google Cloud
  • A VM instance running on Google Cloud
-- rayu
google-cloud-stackdriver
kubernetes
rest
stackdriver

1 Answer

8/30/2018

you need to request per MonitoredResource, which permits instance names and alike... for GCE that would be gce_instance while for GKE it would be container. individual pods of a cluster can be filtered by their cluster_name & pod_id; the documentation for resource-list describes it:

container (GKE Container) A Google Container Engine (GKE) container instance.

project_id: The identifier of the GCP project associated with this resource, such as "my-project".

cluster_name: An immutable name for the cluster the container is running in.

namespace_id: Immutable ID of the cluster namespace the container is running in.

instance_id: Immutable ID of the GCE instance the container is running in.

pod_id: Immutable ID of the pod the container is running in.

container_name: Immutable name of the container.

zone: The GCE zone in which the instance is running.

-- Martin Zeitler
Source: StackOverflow