diff --git a/cluster/addons/fluentd-gcp/fluentd-gcp-image/Dockerfile b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Dockerfile index 89b65d1c01f..7b1ae18bd44 100644 --- a/cluster/addons/fluentd-gcp/fluentd-gcp-image/Dockerfile +++ b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Dockerfile @@ -20,43 +20,39 @@ # scope and that the Logging API has been enabled for the project # in the Google Developer Console. -FROM gcr.io/google_containers/ubuntu-slim:0.6 +FROM gcr.io/google-containers/debian-base-amd64:0.1 -# Disable prompts from apt -ENV DEBIAN_FRONTEND noninteractive +COPY Gemfile /Gemfile -# Install build tools -RUN apt-get -qq update && \ - apt-get install -y -qq curl ca-certificates gcc make bash sudo && \ - apt-get install -y -qq --reinstall lsb-base lsb-release && \ - # Install logging agent and required gems - /usr/bin/curl -sSL https://toolbelt.treasuredata.com/sh/install-ubuntu-xenial-td-agent2.sh | sh && \ - sed -i -e "s/USER=td-agent/USER=root/" -e "s/GROUP=td-agent/GROUP=root/" /etc/init.d/td-agent && \ - td-agent-gem install --no-document fluent-plugin-record-reformer -v 0.8.2 && \ - td-agent-gem install --no-document fluent-plugin-systemd -v 0.0.5 && \ - td-agent-gem install --no-document fluent-plugin-google-cloud -v 0.5.6 && \ - td-agent-gem install --no-document fluent-plugin-detect-exceptions -v 0.0.4 && \ - td-agent-gem install --no-document fluent-plugin-prometheus -v 0.2.1 && \ - # Remove build tools - apt-get remove -y -qq gcc make && \ - apt-get autoremove -y -qq && \ - apt-get clean -qq && \ - # Remove unnecessary files - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ - /opt/td-agent/embedded/share/doc \ - /opt/td-agent/embedded/share/gtk-doc \ - /opt/td-agent/embedded/lib/postgresql \ - /opt/td-agent/embedded/bin/postgres \ - /opt/td-agent/embedded/share/postgresql \ - /etc/td-agent/td-agent.conf +# 1. Install & configure dependencies. +# 2. Install fluentd via ruby. +# 3. Remove build dependencies. +# 4. Cleanup leftover caches & files. +RUN BUILD_DEPS="make gcc g++ libc-dev ruby-dev" \ + && clean-install $BUILD_DEPS \ + ca-certificates \ + libjemalloc1 \ + liblz4-1 \ + ruby \ + && echo 'gem: --no-document' >> /etc/gemrc \ + && gem install --file Gemfile \ + && apt-get purge -y --auto-remove \ + -o APT::AutoRemove::RecommendsImportant=false \ + $BUILD_DEPS \ + && rm -rf /tmp/* \ + /var/lib/apt/lists/* \ + /usr/lib/ruby/gems/*/cache/*.gem \ + /var/log/* \ + /var/tmp/* # Copy the Fluentd configuration file for logging Docker container logs. -COPY fluent.conf /etc/td-agent/td-agent.conf - -# Copy the entrypoint for the container +COPY fluent.conf /etc/fluent/fluent.conf COPY run.sh /run.sh +# Expose prometheus metrics. EXPOSE 80 +ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1 + # Start Fluentd to pick up our config that watches Docker container logs. CMD /run.sh $FLUENTD_ARGS diff --git a/cluster/addons/fluentd-gcp/fluentd-gcp-image/Gemfile b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Gemfile new file mode 100644 index 00000000000..ddf668493b9 --- /dev/null +++ b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Gemfile @@ -0,0 +1,9 @@ +source 'https://rubygems.org' + +gem 'fluentd', '~>0.12.32' +gem 'fluent-plugin-record-reformer', '~>0.8.3' +gem 'fluent-plugin-systemd', '~>0.0.7' +gem 'fluent-plugin-google-cloud', '~>0.5.6' +gem 'fluent-plugin-detect-exceptions', '~>0.0.5' +gem 'fluent-plugin-prometheus', '~>0.2.1' +gem 'oj', '~>2.18.1' diff --git a/cluster/addons/fluentd-gcp/fluentd-gcp-image/Makefile b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Makefile index cdf36cc31a9..a2f72515457 100644 --- a/cluster/addons/fluentd-gcp/fluentd-gcp-image/Makefile +++ b/cluster/addons/fluentd-gcp/fluentd-gcp-image/Makefile @@ -25,8 +25,8 @@ .PHONY: build push -PREFIX=gcr.io/google_containers -TAG = 1.40 +PREFIX=gcr.io/google-containers +TAG = 2.0 build: docker build --pull -t $(PREFIX)/fluentd-gcp:$(TAG) . diff --git a/cluster/addons/fluentd-gcp/fluentd-gcp-image/README.md b/cluster/addons/fluentd-gcp/fluentd-gcp-image/README.md index a663d2f131b..853aa5457a1 100644 --- a/cluster/addons/fluentd-gcp/fluentd-gcp-image/README.md +++ b/cluster/addons/fluentd-gcp/fluentd-gcp-image/README.md @@ -6,6 +6,20 @@ This image is designed to be used as part of the [Kubernetes](https://github.com cluster bring up process. The image resides at DockerHub under the name [kubernetes/fluentd-gcp](https://registry.hub.docker.com/u/kubernetes/fluentd-gcp/). +# Usage + +The image is built with its own set of plugins which you can later use +in the configuration. The set of plugin is enumerated in a Gemfile in the +image's directory. You can find details about fluentd configuration on the +[official site](http://docs.fluentd.org/articles/config-file). + +In order to configure fluentd image, you should mount a directory with `.conf` +files to `/etc/fluent/config.d` or add files to that directory by building +a new image on top. All `.conf` files in the `/etc/fluent/config.d` directory +will be included to the final fluentd configuration. + +Command line arguments to the fluentd executable are passed +via environment variable `FLUENTD_ARGS`. [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/fluentd-gcp/fluentd-gcp-image/README.md?pixel)]() diff --git a/cluster/addons/fluentd-gcp/fluentd-gcp-image/fluent.conf b/cluster/addons/fluentd-gcp/fluentd-gcp-image/fluent.conf index 3ca289232bf..a73db5d7c70 100644 --- a/cluster/addons/fluentd-gcp/fluentd-gcp-image/fluent.conf +++ b/cluster/addons/fluentd-gcp/fluentd-gcp-image/fluent.conf @@ -1,395 +1,8 @@ -# This configuration file for Fluentd / td-agent is used -# to watch changes to Docker log files that live in the -# directory /var/lib/docker/containers/ and are symbolically -# linked to from the /var/log directory using names that capture the -# pod name and container name. These logs are then submitted to -# Google Cloud Logging which assumes the installation of the cloud-logging plug-in. -# -# Example -# ======= -# A line in the Docker log file might like like this JSON: -# -# {"log":"2014/09/25 21:15:03 Got request with path wombat\n", -# "stream":"stderr", -# "time":"2014-09-25T21:15:03.499185026Z"} -# -# The record reformer is used to write the tag to focus on the pod name -# and the Kubernetes container name. For example a Docker container's logs -# might be in the directory: -# /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b -# and in the file: -# 997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log -# where 997599971ee6... is the Docker ID of the running container. -# The Kubernetes kubelet makes a symbolic link to this file on the host machine -# in the /var/log/containers directory which includes the pod name and the Kubernetes -# container name: -# synthetic-logger-0.25lps-pod_default-synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log -# -> -# /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log -# The /var/log directory on the host is mapped to the /var/log directory in the container -# running this instance of Fluentd and we end up collecting the file: -# /var/log/containers/synthetic-logger-0.25lps-pod_default-synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log -# This results in the tag: -# var.log.containers.synthetic-logger-0.25lps-pod_default-synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log -# The record reformer is used is discard the var.log.containers prefix and -# the Docker container ID suffix and "kubernetes." is pre-pended giving the -# final tag which is ingested into Elasticsearch: -# kubernetes.synthetic-logger-0.25lps-pod_default-synth-lgr -# This makes it easier for users to search for logs by pod name or by -# the name of the Kubernetes container regardless of how many times the -# Kubernetes pod has been restarted (resulting in a several Docker container IDs). +# This is the root config file, which only includes components of the actual configuration -# Prevent fluentd from handling records containing its own logs. Otherwise -# it can lead to an infinite loop, when error in sending one message generates -# another message which also fails to be sent and so on. +# Do not collect fluentd's own logs to avoid infinite loops. type null -# Example: -# {"log":"[info:2016-02-16T16:04:05.930-08:00] Some log text here\n","stream":"stdout","time":"2016-02-17T00:04:05.931087621Z"} - - type tail - format json - time_key time - path /var/log/containers/*.log - pos_file /var/log/gcp-containers.log.pos - time_format %Y-%m-%dT%H:%M:%S.%N%Z - tag reform.* - read_from_head true - - - - type parser - format /^(?\w)(? - - - type record_reformer - enable_ruby true - tag raw.kubernetes.${tag_suffix[4].split('-')[0..-2].join('-')} - - -# Detect exceptions in the log output and forward them as one log entry. - - @type copy - - - @type prometheus - - - type counter - name logging_line_count - desc Total number of lines generated by application containers - - tag ${tag} - - - - - @type detect_exceptions - - remove_tag_prefix raw - message log - stream stream - multiline_flush_interval 5 - max_bytes 500000 - max_lines 1000 - - - -# Example: -# 2015-12-21 23:17:22,066 [salt.state ][INFO ] Completed state [net.ipv4.ip_forward] at time 23:17:22.066081 - - type tail - format /^(?