From a503fecec1df77fe4313ae1f989d0f251583371a Mon Sep 17 00:00:00 2001 From: Alex Robinson Date: Wed, 22 Apr 2015 21:09:43 +0000 Subject: [PATCH] Add an example usage of the cloud logging sidecar image to the same directory as the image components. It doesn't really belong under examples/ since it's so specific to GCE/GKE. --- contrib/logging/fluentd-sidecar-gcp/README.md | 25 ++++++++++++++---- .../logging-sidecar-example.yaml | 26 +++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 contrib/logging/fluentd-sidecar-gcp/logging-sidecar-example.yaml diff --git a/contrib/logging/fluentd-sidecar-gcp/README.md b/contrib/logging/fluentd-sidecar-gcp/README.md index fb891b19886..6ae6a1f70e8 100644 --- a/contrib/logging/fluentd-sidecar-gcp/README.md +++ b/contrib/logging/fluentd-sidecar-gcp/README.md @@ -1,8 +1,23 @@ # Collecting log files from within containers with Fluentd and sending to the Google Cloud Logging service. This directory contains the source files needed to make a Docker image that collects log files from arbitrary files within a container using [Fluentd](http://www.fluentd.org/) and sends them to GCP. -This image is designed to be used as a sidecar container as part of a [Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes) pod. -The image resides at DockerHub under the name -[kubernetes/fluentd-sidecar-gcp](https://registry.hub.docker.com/u/kubernetes/fluentd-sidecar-gcp/). +The image is designed to be used as a sidecar container as part of a pod. +It lives in the Google Container Registry under the name `gcr.io/google_containers/fluentd-sidecar-gcp`. -# TODO: Add example pod config. -# TODO: say that it resides at gcr.io instead? +This shouldn't be necessary if your container writes its logs to stdout or stderr, since the Kubernetes cluster's default logging infrastructure will collect that automatically, but this is useful if your application logs to a specific file in its filesystem and can't easily be changed. + +In order to make this work, you have to add a few things to your pod config: + +1. A second container, using the `gcr.io/google_containers/fluentd-sidecar-gcp:1.0` image to send the logs to Google Cloud Logging. +2. A volume for the two containers to share. The emptyDir volume type is a good choice for this because we only want the volume to exist for the lifetime of the pod. +3. Mount paths for the volume in each container. In your primary container, this should be the path that the applications log files are written to. In the secondary container, this can be just about anything, so we put it under /mnt/log to keep it out of the way of the rest of the filesystem. +4. The `FILES_TO_COLLECT` environment variable in the sidecar container, telling it which files to collect logs from. These paths should always be in the mounted volume. + +To try it out, make sure that your cluster was set up to log to Google Cloud Logging when it was created (i.e. you set `LOGGING_DESTINATION=gcp` or are running on Container Engine), then simply run +``` +kubectl create -f logging-sidecar-pod.yaml +``` + +You should see the logs show up in the log viewer of the Google Developer Console shortly after creating the pod. To clean up after yourself, simply run +``` +kubectl delete -f logging-sidecar-pod.yaml +``` diff --git a/contrib/logging/fluentd-sidecar-gcp/logging-sidecar-example.yaml b/contrib/logging/fluentd-sidecar-gcp/logging-sidecar-example.yaml new file mode 100644 index 00000000000..e83fe93171d --- /dev/null +++ b/contrib/logging/fluentd-sidecar-gcp/logging-sidecar-example.yaml @@ -0,0 +1,26 @@ +apiVersion: v1beta3 +kind: Pod +metadata: + labels: + example: logging-sidecar + name: logging-sidecar-example +spec: + containers: + - name: synthetic-logger + image: ubuntu:14.04 + command: ["bash", "-c", "i=\"0\"; while true; do echo \"`hostname`: $i \" >> /var/log/synthetic-count.log; date --rfc-3339 ns >> /var/log/synthetic-dates.log; sleep 4; i=$[$i+1]; done"] + volumeMounts: + - name: log-storage + mountPath: /var/log + - name: sidecar-log-collector + image: gcr.io/google_containers/fluentd-sidecar-gcp:1.0 + env: + - name: FILES_TO_COLLECT + value: "/mnt/log/synthetic-count.log /mnt/log/synthetic-dates.log" + volumeMounts: + - name: log-storage + readOnly: true + mountPath: /mnt/log + volumes: + - name: log-storage + emptyDir: {}