Commit 70b4db20 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50082 from crassirostris/cleanup-fluentd-es

Automatic merge from submit-queue (batch tested with PRs 48532, 50054, 50082) Refactored the fluentd-es addon Refactor fluentd-elasticsearch addon: - Decrease the number of files by moving RBAC-related objects in the same files where they're used - Move the fluentd configuration out of the image - Don't use PVC to avoid leaking resources in e2e tests - Fluentd now ingest docker and kubelet logs that are written to journald - Disable X-Pack, because it's not free Fixes https://github.com/kubernetes/kubernetes/issues/41462 Fixes https://github.com/kubernetes/kubernetes/issues/49816 Fixes https://github.com/kubernetes/kubernetes/issues/48973 Fixes https://github.com/kubernetes/kubernetes/issues/49450 @aknuds1 @coffeepac Could you please take a look? ```release-note Fluentd DaemonSet in the fluentd-elasticsearch addon is configured via ConfigMap and includes journald plugin Elasticsearch StatefulSet in the fluentd-elasticsearch addon uses local storage instead of PVC by default ```
parents 40b4f77a 46f53dae
# Elasticsearch Add-On # Elasticsearch Add-On
This add-on consists of a combination of
[Elasticsearch](https://www.elastic.co/products/elasticsearch), [Fluentd](http://www.fluentd.org/) This add-on consists of a combination of [Elasticsearch][elasticsearch],
and [Kibana](https://www.elastic.co/products/elasticsearch). Elasticsearch is a search engine [Fluentd][fluentd] and [Kibana][kibana]. Elasticsearch is a search engine
that is responsible for storing our logs and allowing for them to be queried. Fluentd sends that is responsible for storing our logs and allowing for them to be queried.
log messages from Kubernetes to Elasticsearch, whereas Kibana is a graphical interface for Fluentd sends log messages from Kubernetes to Elasticsearch, whereas Kibana
viewing and querying the logs stored in Elasticsearch. is a graphical interface for viewing and querying the logs stored in
Elasticsearch.
**Note:** this addon should **not** be used as-is in production. This is
an example and you should treat is as such. Please see at least the
[Security](#security) and the [Storage](#storage) sections for more
information.
## Elasticsearch ## Elasticsearch
Elasticsearch is deployed as a
[StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/), which
is like a Deployment, but allows for maintaining state on storage volumes.
### Authentication Elasticsearch is deployed as a [StatefulSet][statefulSet], which is like
Elasticsearch has basic authentication enabled by default, in our configuration the credentials a Deployment, but allows for maintaining state on storage volumes.
are at their default values, i.e. username 'elastic' and password 'changeme'. In order to change
them, please read up on [the official documentation](https://www.elastic.co/guide/en/x-pack/current/setting-up-authentication.html#reset-built-in-user-passwords). ### Security
Elasticsearch has capabilities to enable authorization using
[X-Pack plugin][xPack]. See configuration parameter `xpack.security.enabled`
in Elasticsearch and Kibana configurations. It can also be set via
`XPACK_SECURITY_ENABLED` env variable. After enabling the feature,
follow [official documentation][setupCreds] to set up credentials in
Elasticsearch and Kibana. Don't forget to propagate those credentials also to
Fluentd in its [configuration][fluentdCreds], using for example
[environment variables][fluentdEnvVar]. You can utilize [ConfigMaps][configMap]
and [Secrets][secret] to store credentials in the Kubernetes apiserver.
### Initialization ### Initialization
The Elasticsearch Statefulset manifest specifies that there shall be an The Elasticsearch Statefulset manifest specifies that there shall be an
[init container](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) executing [init container][initContainer] executing before Elasticsearch containers
before Elasticsearch containers themselves, in order to ensure that the kernel state variable themselves, in order to ensure that the kernel state variable
`vm.max_map_count` is at least 262144, since this is a requirement of Elasticsearch. `vm.max_map_count` is at least 262144, since this is a requirement of
You may remove the init container if you know that your host OS meets this requirement. Elasticsearch. You may remove the init container if you know that your host
OS meets this requirement.
### Storage ### Storage
The Elasticsearch StatefulSet will claim a storage volume 'elasticsearch-logging',
of the standard The Elasticsearch StatefulSet will use the [EmptyDir][emptyDir] volume to
[StorageClass](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#storageclasses), store data. EmptyDir is erased when the pod terminates, here it is used only
that by default will be 100 Gi per replica. Please adjust this to your needs (including for testing purposes. **Important:** please change the storage to persistent
possibly choosing a more suitable StorageClass). volume claim before actually using this StatefulSet in your setup!
## Fluentd ## Fluentd
Fluentd is deployed as a
[DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) which spawns a
pod on each node that reads logs, generated by kubelet, container runtime and containers and
sends them to Elasticsearch.
*Please note that for Fluentd to work, every Kubernetes node must be labeled* Fluentd is deployed as a [DaemonSet][daemonSet] which spawns a pod on each
`beta.kubernetes.io/fluentd-ds-ready=true`, as otherwise Fluentd will ignore them. node that reads logs, generated by kubelet, container runtime and containers
and sends them to Elasticsearch.
Learn more at: https://kubernetes.io/docs/tasks/debug-application-cluster/logging-elasticsearch-kibana **Note:** in order for Fluentd to work, every Kubernetes node must be labeled
with `beta.kubernetes.io/fluentd-ds-ready=true`, as otherwise the Fluentd
DaemonSet will ignore them.
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/fluentd-elasticsearch/README.md?pixel)]() Learn more in the [official Kubernetes documentation][k8sElasticsearchDocs].
### Known problems
Since Fluentd talks to the Elasticsearch service inside the cluster, instances
on masters won't work, because masters have no kube-proxy. Don't mark masters
with a label mentioned in the previous paragraph or add a taint on them to
avoid Fluentd pods scheduling there.
[fluentd]: http://www.fluentd.org/
[elasticsearch]: https://www.elastic.co/products/elasticsearch
[kibana]: https://www.elastic.co/products/kibana
[xPack]: https://www.elastic.co/products/x-pack
[setupCreds]: https://www.elastic.co/guide/en/x-pack/current/setting-up-authentication.html#reset-built-in-user-passwords
[fluentdCreds]: https://github.com/uken/fluent-plugin-elasticsearch#user-password-path-scheme-ssl_verify
[fluentdEnvVar]: https://docs.fluentd.org/v0.12/articles/faq#how-can-i-use-environment-variables-to-configure-parameters-dynamically
[configMap]: https://kubernetes.io/docs/tasks/configure-pod-container/configmap/
[secret]: https://kubernetes.io/docs/concepts/configuration/secret/
[statefulSet]: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset
[initContainer]: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
[emptyDir]: https://kubernetes.io/docs/concepts/storage/volumes#emptydir
[daemonSet]: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/
[k8sElasticsearchDocs]: https://kubernetes.io/docs/tasks/debug-application-cluster/logging-elasticsearch-kibana
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/fluentd-elasticsearch/README.md?pixel)]()
apiVersion: v1
kind: ConfigMap
metadata:
name: environment
namespace: kube-system
data:
elasticsearch-user: elastic
apiVersion: v1
kind: Secret
metadata:
name: environment
namespace: kube-system
type: Opaque
data:
elasticsearch-password: Y2hhbmdlbWU=
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: elasticsearch-logging
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
rules:
- apiGroups:
- ""
resources:
- "services"
- "namespaces"
- "endpoints"
verbs:
- "get"
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: kube-system
name: elasticsearch-logging
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
subjects:
- kind: ServiceAccount
name: elasticsearch-logging
namespace: kube-system
apiGroup: ""
roleRef:
kind: ClusterRole
name: elasticsearch-logging
apiGroup: ""
...@@ -14,22 +14,12 @@ ...@@ -14,22 +14,12 @@
FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.1 FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.1
USER root
RUN mkdir /data
RUN chown -R elasticsearch:elasticsearch /data
WORKDIR /usr/share/elasticsearch
VOLUME ["/data"] VOLUME ["/data"]
EXPOSE 9200 9300 EXPOSE 9200 9300
USER elasticsearch COPY elasticsearch_logging_discovery run.sh bin/
COPY elasticsearch_logging_discovery bin/ COPY config/elasticsearch.yml config/log4j2.properties config/
COPY config/elasticsearch.yml config/
COPY config/log4j2.properties config/
COPY run.sh bin/
USER root USER root
RUN chown -R elasticsearch:elasticsearch config RUN chown -R elasticsearch:elasticsearch ./
CMD ["bin/run.sh"] CMD ["bin/run.sh"]
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
.PHONY: elasticsearch_logging_discovery build push .PHONY: binary build push
# The current value of the tag to be used for building and PREFIX = gcr.io/google-containers
# pushing an image to gcr.io IMAGE = elasticsearch
TAG = v5.5.1 TAG = v5.5.1-1
build: elasticsearch_logging_discovery build:
docker build --pull -t gcr.io/google_containers/elasticsearch:$(TAG) . docker build --pull -t $(PREFIX)/$(IMAGE):$(TAG) .
push: push:
gcloud docker -- push gcr.io/google_containers/elasticsearch:$(TAG) gcloud docker -- push $(PREFIX)/$(IMAGE):$(TAG)
elasticsearch_logging_discovery: binary:
CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-w" elasticsearch_logging_discovery.go CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-w" elasticsearch_logging_discovery.go
clean: clean:
......
...@@ -12,3 +12,6 @@ path.data: /data ...@@ -12,3 +12,6 @@ path.data: /data
network.host: 0.0.0.0 network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: ${MINIMUM_MASTER_NODES} discovery.zen.minimum_master_nodes: ${MINIMUM_MASTER_NODES}
xpack.security.enabled: false
xpack.monitoring.enabled: false
apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
version: v1
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
# RBAC authn and authz
apiVersion: v1
kind: ServiceAccount
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: elasticsearch-logging
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
rules:
- apiGroups:
- ""
resources:
- "services"
- "namespaces"
- "endpoints"
verbs:
- "get"
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: kube-system
name: elasticsearch-logging
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
subjects:
- kind: ServiceAccount
name: elasticsearch-logging
namespace: kube-system
apiGroup: ""
roleRef:
kind: ClusterRole
name: elasticsearch-logging
apiGroup: ""
---
# Elasticsearch deployment itself
apiVersion: apps/v1beta1 apiVersion: apps/v1beta1
kind: StatefulSet kind: StatefulSet
metadata: metadata:
name: elasticsearch-logging-v1 name: elasticsearch-logging
namespace: kube-system namespace: kube-system
labels: labels:
k8s-app: elasticsearch-logging k8s-app: elasticsearch-logging
version: v1 version: v5.5.1
kubernetes.io/cluster-service: "true" kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile addonmanager.kubernetes.io/mode: Reconcile
spec: spec:
...@@ -14,17 +63,17 @@ spec: ...@@ -14,17 +63,17 @@ spec:
selector: selector:
matchLabels: matchLabels:
k8s-app: elasticsearch-logging k8s-app: elasticsearch-logging
version: v1 version: v5.5.1
template: template:
metadata: metadata:
labels: labels:
k8s-app: elasticsearch-logging k8s-app: elasticsearch-logging
version: v1 version: v5.5.1
kubernetes.io/cluster-service: "true" kubernetes.io/cluster-service: "true"
spec: spec:
serviceAccountName: elasticsearch-logging serviceAccountName: elasticsearch-logging
containers: containers:
- image: gcr.io/google_containers/elasticsearch:v5.5.1 - image: gcr.io/google-containers/elasticsearch:v5.5.1-1
name: elasticsearch-logging name: elasticsearch-logging
resources: resources:
# need more cpu upon initialization, therefore burstable class # need more cpu upon initialization, therefore burstable class
...@@ -47,17 +96,15 @@ spec: ...@@ -47,17 +96,15 @@ spec:
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.namespace fieldPath: metadata.namespace
volumes:
- name: elasticsearch-logging
emptyDir: {}
# Elasticsearch requires vm.max_map_count to be at least 262144.
# If your OS already sets up this number to a higher value, feel free
# to remove this init container.
initContainers: initContainers:
- image: alpine:3.6 - image: alpine:3.6
command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"] command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
name: elasticsearch-logging-init name: elasticsearch-logging-init
securityContext: securityContext:
privileged: true privileged: true
volumeClaimTemplates:
- metadata:
name: elasticsearch-logging
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 100Gi
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: fluentd-es
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
rules:
- apiGroups:
- ""
resources:
- "namespaces"
- "pods"
verbs:
- "get"
- "watch"
- "list"
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: fluentd-es
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
subjects:
- kind: ServiceAccount
name: fluentd-es
namespace: kube-system
apiGroup: ""
roleRef:
kind: ClusterRole
name: fluentd-es
apiGroup: ""
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd-es
namespace: kube-system
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: fluentd-es
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
rules:
- apiGroups:
- ""
resources:
- "namespaces"
- "pods"
verbs:
- "get"
- "watch"
- "list"
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: fluentd-es
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
subjects:
- kind: ServiceAccount
name: fluentd-es
namespace: kube-system
apiGroup: ""
roleRef:
kind: ClusterRole
name: fluentd-es
apiGroup: ""
---
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
kind: DaemonSet kind: DaemonSet
metadata: metadata:
name: fluentd-es-v1.24 name: fluentd-es
namespace: kube-system namespace: kube-system
labels: labels:
k8s-app: fluentd-es k8s-app: fluentd-es
version: v2.0.0
kubernetes.io/cluster-service: "true" kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile addonmanager.kubernetes.io/mode: Reconcile
version: v1.24
spec: spec:
template: template:
metadata: metadata:
labels: labels:
k8s-app: fluentd-es k8s-app: fluentd-es
kubernetes.io/cluster-service: "true" kubernetes.io/cluster-service: "true"
version: v1.24 version: v2.0.0
# This annotation ensures that fluentd does not get evicted if the node # This annotation ensures that fluentd does not get evicted if the node
# supports critical pod annotation based priority scheme. # supports critical pod annotation based priority scheme.
# Note that this does not guarantee admission on the nodes (#40573). # Note that this does not guarantee admission on the nodes (#40573).
...@@ -24,27 +71,13 @@ spec: ...@@ -24,27 +71,13 @@ spec:
serviceAccountName: fluentd-es serviceAccountName: fluentd-es
containers: containers:
- name: fluentd-es - name: fluentd-es
image: gcr.io/google_containers/fluentd-elasticsearch:1.24 image: gcr.io/google-containers/fluentd-elasticsearch:v2.0.0
command:
- '/bin/sh'
- '-c'
- '/usr/sbin/td-agent $FLUENTD_ARGS'
env: env:
- name: FLUENTD_ARGS - name: FLUENTD_ARGS
value: -q value: --no-supervisor -q
- name: FLUENT_ELASTICSEARCH_USER
valueFrom:
configMapKeyRef:
name: environment
key: elasticsearch-user
- name: FLUENT_ELASTICSEARCH_PASSWORD
valueFrom:
secretKeyRef:
name: environment
key: elasticsearch-password
resources: resources:
limits: limits:
memory: 200Mi memory: 500Mi
requests: requests:
cpu: 100m cpu: 100m
memory: 200Mi memory: 200Mi
...@@ -54,6 +87,11 @@ spec: ...@@ -54,6 +87,11 @@ spec:
- name: varlibdockercontainers - name: varlibdockercontainers
mountPath: /var/lib/docker/containers mountPath: /var/lib/docker/containers
readOnly: true readOnly: true
- name: libsystemddir
mountPath: /host/lib
readOnly: true
- name: config-volume
mountPath: /etc/fluent/config.d
nodeSelector: nodeSelector:
beta.kubernetes.io/fluentd-ds-ready: "true" beta.kubernetes.io/fluentd-ds-ready: "true"
terminationGracePeriodSeconds: 30 terminationGracePeriodSeconds: 30
...@@ -64,3 +102,10 @@ spec: ...@@ -64,3 +102,10 @@ spec:
- name: varlibdockercontainers - name: varlibdockercontainers
hostPath: hostPath:
path: /var/lib/docker/containers path: /var/lib/docker/containers
# It is needed to copy systemd library to decompress journals
- name: libsystemddir
hostPath:
path: /usr/lib64
- name: config-volume
configMap:
name: fluentd-es-config-v0.1.0
...@@ -15,28 +15,45 @@ ...@@ -15,28 +15,45 @@
# This Dockerfile will build an image that is configured # This Dockerfile will build an image that is configured
# to run Fluentd with an Elasticsearch plug-in and the # to run Fluentd with an Elasticsearch plug-in and the
# provided configuration file. # provided configuration file.
# TODO(a-robinson): Use a lighter base image, e.g. some form of busybox.
# The image acts as an executable for the binary /usr/sbin/td-agent. # The image acts as an executable for the binary /usr/sbin/td-agent.
# Note that fluentd is run with root permssion to allow access to # Note that fluentd is run with root permssion to allow access to
# log files with root only access under /var/log/containers/* # log files with root only access under /var/log/containers/*
# Please see http://docs.fluentd.org/articles/install-by-deb for more
# information about installing fluentd using deb package.
FROM gcr.io/google_containers/ubuntu-slim:0.6 FROM gcr.io/google-containers/debian-base-amd64:0.1
# Ensure there are enough file descriptors for running Fluentd. COPY Gemfile /Gemfile
RUN ulimit -n 65536
# 1. Install & configure dependencies.
# Disable prompts from apt. # 2. Install fluentd via ruby.
ENV DEBIAN_FRONTEND noninteractive # 3. Remove build dependencies.
# 4. Cleanup leftover caches & files.
# Copy the Fluentd configuration file. RUN BUILD_DEPS="make gcc g++ libc6-dev ruby-dev" \
COPY td-agent.conf /etc/td-agent/td-agent.conf && clean-install $BUILD_DEPS \
ca-certificates \
COPY build.sh /tmp/build.sh libjemalloc1 \
RUN /tmp/build.sh liblz4-1 \
ruby \
ENV LD_PRELOAD /opt/td-agent/embedded/lib/libjemalloc.so && echo 'gem: --no-document' >> /etc/gemrc \
&& gem install --file Gemfile \
# Run the Fluentd service. && apt-get purge -y --auto-remove \
ENTRYPOINT ["td-agent"] -o APT::AutoRemove::RecommendsImportant=false \
$BUILD_DEPS \
&& rm -rf /tmp/* \
/var/lib/apt/lists/* \
/usr/lib/ruby/gems/*/cache/*.gem \
/var/log/* \
/var/tmp/* \
# Ensure fluent has enough file descriptors
&& ulimit -n 65536
# Copy the Fluentd configuration file for logging Docker container logs.
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
source 'https://rubygems.org'
gem 'fluentd', '~>0.12.32'
gem 'activesupport', '~>4.2.6'
gem 'fluent-plugin-kubernetes_metadata_filter', '~>0.27.0'
gem 'fluent-plugin-elasticsearch', '~>1.9.5'
gem 'fluent-plugin-systemd', '~>0.0.8'
gem 'fluent-plugin-prometheus', '~>0.3.0'
gem 'oj', '~>2.18.1'
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
.PHONY: build push .PHONY: build push
PREFIX = gcr.io/google_containers PREFIX = gcr.io/google-containers
IMAGE = fluentd-elasticsearch IMAGE = fluentd-elasticsearch
TAG = 1.24 TAG = v2.0.0
build: build:
docker build --pull -t $(PREFIX)/$(IMAGE):$(TAG) . docker build --pull -t $(PREFIX)/$(IMAGE):$(TAG) .
push: push:
gcloud docker --server=gcr.io -- push $(PREFIX)/$(IMAGE):$(TAG) gcloud docker -- push $(PREFIX)/$(IMAGE):$(TAG)
# Collecting Docker Log Files with Fluentd and Elasticsearch # Collecting Docker Log Files with Fluentd and Elasticsearch
This directory contains the source files needed to make a Docker image This directory contains the source files needed to make a Docker image
that collects Docker container log files using [Fluentd](http://www.fluentd.org/) that collects Docker container log files using [Fluentd][fluentd]
and sends them to an instance of [Elasticsearch](http://www.elasticsearch.org/). and sends them to an instance of [Elasticsearch][elasticsearch].
This image is designed to be used as part of the [Kubernetes](https://github.com/kubernetes/kubernetes) This image is designed to be used as part of the [Kubernetes][kubernetes]
cluster bring up process. The image resides at DockerHub under the name cluster bring up process. The image resides at GCR under the name
[kubernetes/fluentd-elasticsearch](https://registry.hub.docker.com/u/kubernetes/fluentd-elasticsearch/). [gcr.io/google-containers/fluentd-elasticsearch][image].
[fluentd]: http://www.fluentd.org/
[elasticsearch]: https://www.elastic.co/products/elasticsearch
[kubernetes]: https://kubernetes.io
[image]: https://gcr.io/google-containers/fluentd-elasticsearch
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/fluentd-elasticsearch/fluentd-es-image/README.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/fluentd-elasticsearch/fluentd-es-image/README.md?pixel)]()
#!/bin/sh
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Install prerequisites.
apt-get update
apt-get install -y -q --no-install-recommends \
curl ca-certificates make g++ sudo bash
# Install Fluentd.
/usr/bin/curl -sSL https://toolbelt.treasuredata.com/sh/install-ubuntu-xenial-td-agent2.sh | sh
# Change the default user and group to root.
# Needed to allow access to /var/log/docker/... files.
sed -i -e "s/USER=td-agent/USER=root/" -e "s/GROUP=td-agent/GROUP=root/" /etc/init.d/td-agent
# Install the Elasticsearch Fluentd plug-in.
# http://docs.fluentd.org/articles/plugin-management
td-agent-gem install --no-document fluent-plugin-kubernetes_metadata_filter -v 0.27.0
td-agent-gem install --no-document fluent-plugin-elasticsearch -v 1.9.5
td-agent-gem install --no-document fluent-plugin-prometheus -v 0.3.0
# Remove docs and postgres references
rm -rf /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
apt-get remove -y make g++
apt-get autoremove -y
apt-get clean -y
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# This is the root config file, which only includes components of the actual configuration
# Do not collect fluentd's own logs to avoid infinite loops.
<match fluent.**>
type null
</match>
@include /etc/fluent/config.d/*.conf
#!/bin/sh
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# These steps must be executed once the host /var and /lib volumes have
# been mounted, and therefore cannot be done in the docker build stage.
# For systems without journald
mkdir -p /var/log/journal
# Copy host libsystemd into image to avoid compatibility issues.
if [ ! -z "$(ls /host/lib/libsystemd* 2>/dev/null)" ]; then
rm /lib/x86_64-linux-gnu/libsystemd*
cp -a /host/lib/libsystemd* /lib/x86_64-linux-gnu/
fi
/usr/local/bin/fluentd $@
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd-es
namespace: kube-system
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
...@@ -27,10 +27,14 @@ spec: ...@@ -27,10 +27,14 @@ spec:
requests: requests:
cpu: 100m cpu: 100m
env: env:
- name: "ELASTICSEARCH_URL" - name: ELASTICSEARCH_URL
value: "http://elasticsearch-logging:9200" value: http://elasticsearch-logging:9200
- name: "SERVER_BASEPATH" - name: SERVER_BASEPATH
value: "/api/v1/proxy/namespaces/kube-system/services/kibana-logging" value: /api/v1/proxy/namespaces/kube-system/services/kibana-logging
- name: XPACK_MONITORING_ENABLED
value: "false"
- name: XPACK_SECURITY_ENABLED
value: "false"
ports: ports:
- containerPort: 5601 - containerPort: 5601
name: ui name: ui
......
...@@ -28,15 +28,6 @@ spec: ...@@ -28,15 +28,6 @@ spec:
containers: containers:
- name: fluentd-gcp - name: fluentd-gcp
image: gcr.io/google-containers/fluentd-gcp:2.0.8 image: gcr.io/google-containers/fluentd-gcp:2.0.8
# If fluentd consumes its own logs, the following situation may happen:
# fluentd fails to send a chunk to the server => writes it to the log =>
# tries to send this message to the server => fails to send a chunk and so on.
# Writing to a file, which is not exported to the back-end prevents it.
# It also allows to increase the fluentd verbosity by default.
command:
- '/bin/sh'
- '-c'
- '/run.sh $FLUENTD_ARGS'
env: env:
- name: FLUENTD_ARGS - name: FLUENTD_ARGS
value: --no-supervisor -q value: --no-supervisor -q
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment