Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Kustomize base for fluent-bit #90

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a6ec71d
Update README.md
DrMavenRebe Dec 28, 2018
d326f8e
fix: nginx parser regex
edsiper Mar 25, 2019
f711675
Merge branch 'master' of https://github.com/fluent/fluent-bit-kuberne…
julienvincent Apr 12, 2019
531a6a7
fix: typo in readme
Oct 19, 2018
36b3ab5
Update labels to Kubernetes recommended naming scheme
karlskewes Nov 3, 2018
d3fd620
Update README.md
davidkarlsen Sep 24, 2019
a8d9bd6
Updating api endpoint and selector
rjshrjndrn Jan 10, 2020
105fa63
Fix duplication of 'Fluent Bit to Elasticsearch on Minikube' section …
iyankovsky Oct 20, 2020
46d321e
Merge #34 into kustomize-base
solsson Aug 10, 2021
fa55a41
Merge #37 into kustomize-base
solsson Aug 10, 2021
4252f35
Merge fluent/fluent-bit-kubernetes-logging#45 into kustomize-base
solsson Aug 10, 2021
ad4f7a2
Merge fluent/fluent-bit-kubernetes-logging#51 into kustomize-base
solsson Aug 10, 2021
b344a3a
Merge fluent/fluent-bit-kubernetes-logging#57 into kustomize-base
solsson Aug 10, 2021
95e12dd
Merge fluent/fluent-bit-kubernetes-logging#66 into kustomize-base
solsson Aug 10, 2021
3a18cdc
Revert "Update README.md"
solsson Aug 10, 2021
92f6d35
Merge fluent/fluent-bit-kubernetes-logging#84 into kustomize-base
solsson Aug 10, 2021
6f7b856
Starts the Kustomize base from the elasticsearch example
solsson Aug 10, 2021
fcd5622
Fixes label inconsistencies
solsson Aug 10, 2021
6fa4824
Removes deprecated label, kubernetes/kubernetes#72757
solsson Aug 10, 2021
072a479
I think the yaml ordering aimed to keep volumes and volumeMounts
solsson Aug 10, 2021
e69e738
The limit for graceful node shutdown
solsson Aug 10, 2021
1c2091d
There's no indication that the duplication is needed
solsson Aug 10, 2021
d5186b9
Removes stuff that is better handled with Kustomize
solsson Aug 10, 2021
38b56e8
Ports current elasticsearch config to Kustomize
solsson Aug 10, 2021
e0e0289
Removes redundant suffix and prefix
solsson Aug 10, 2021
2095951
Migrates RBAC to Kustomize
solsson Aug 10, 2021
9d649e0
With image digests we don't depend on a particular imagePullPolicy
solsson Aug 10, 2021
f99ebff
Probes from the helm chart
solsson Aug 10, 2021
3dd95af
A decent devloop
solsson Aug 11, 2021
724c616
The docker parser has no effect, but cri has
solsson Aug 11, 2021
4b0736e
Allows custom parsers without duplication of the cri conf
solsson Aug 11, 2021
1786335
Uses the same key for log content as with unparsed logs
solsson Aug 11, 2021
d529507
Merge branch 'base-output-stdout' into kustomize-base
solsson Aug 11, 2021
9b714d4
Seems like something you need to tweak
solsson Aug 11, 2021
cbb9dae
Adapts tag regex to path /var/log/pods
solsson Aug 11, 2021
70562dd
Msgpack format is more useful for devloops because it includes tags
solsson Aug 11, 2021
a5c7b19
Loki with ephemeral storage
solsson Aug 11, 2021
d99ccdb
Easier to follow with the constant length UUID first
solsson Aug 11, 2021
0da56f8
Now includes container metadata and pod labels
solsson Aug 11, 2021
efb12ac
Current from the helm chart
solsson Aug 12, 2021
6d3e74a
Ephemeral loki setup
solsson Aug 13, 2021
0ace3c1
Dropping the dash because it's used as separator everywhere else
solsson Aug 13, 2021
24fb8c4
A dev stack with loki, minimal parsing upfront
solsson Aug 13, 2021
c0b209e
Extracts debug behavior to a patch that can be commented out
solsson Aug 13, 2021
e801dbe
Merge branch 'loki-config' into kustomize-base
solsson Aug 13, 2021
63b006d
Fix indentation
solsson Aug 13, 2021
cae23c9
Restores the official image's config path
solsson Aug 14, 2021
05dbf8d
Using the go plugin we can send the .log record as log line
solsson Aug 14, 2021
f130d8d
Grafana's build is also based on the fluent-bit 1.8.3 image
solsson Aug 14, 2021
de8c0b2
A loki test/examples job that can be applied with -k or -f
solsson Aug 14, 2021
614ea0a
Was meant for the kustomize-base-loki-distributed branch
solsson Aug 14, 2021
d7805fb
Use the exclusion annotation for anything but promtail itself
solsson Aug 15, 2021
79771fb
Tests can fail explicitly with exit 1 where desired
solsson Aug 15, 2021
a81086c
Adds metrics and exec example for the test job
solsson Aug 15, 2021
3426a37
Getting error "TCPTransport: unknown message type" msgType=G
solsson Aug 15, 2021
a77aa02
I can't see any effect of the "wildcard" toleration
solsson Aug 15, 2021
3f7e32b
Removes the old Kafka REST example
solsson Aug 15, 2021
adab693
We could add more base folders to restore Elasticsearch and Kafka
solsson Aug 15, 2021
c1a93cb
When distribution works there's no need for a wait before query
solsson Aug 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Kubernetes Logging with Fluent Bit



[Fluent Bit](http://fluentbit.io) is a lightweight and extensible __Log Processor__ that comes with full support for Kubernetes:

- Read Kubernetes/Docker log files from the file system or through systemd Journal
Expand All @@ -16,72 +14,36 @@ This repository contains a set of Yaml files to deploy Fluent Bit which consider

```
$ kubectl create namespace logging
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-service-account.yaml
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-role.yaml
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-role-binding.yaml
$ kubectl apply -k ./base
```

(`./base` can be replaced with a URL if [#90](https://github.com/fluent/fluent-bit-kubernetes-logging/pull/90) gets merged)

If you are deploying fluent-bit on openshift, you additionally need to run:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/fluent-bit-openshift-security-context-constraints.yaml
```

#### Fluent Bit to Elasticsearch

The next step is to create a ConfigMap that will be used by our Fluent Bit DaemonSet:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-configmap.yaml
```

If the cluster uses a CRI runtime, like containerd or CRI-O, change the `Parser` described in `input-kubernetes.conf` from docker to cri.

Fluent Bit DaemonSet ready to be used with Elasticsearch on a normal Kubernetes Cluster:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-ds.yaml
```

#### Fluent Bit to Elasticsearch on Minikube

If you are using Minikube for testing purposes, use the following alternative DaemonSet manifest:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-ds-minikube.yaml
```

#### Fluent Bit to Kafka

Create a ConfigMap that will be used by our Fluent Bit DaemonSet:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/kafka/fluent-bit-configmap.yaml
```

Fluent Bit DaemonSet ready to be used with Kafka on a normal Kubernetes Cluster:
The base only configures [Stdout](https://docs.fluentbit.io/manual/pipeline/outputs/standard-output) output.
Log records are found using `kubectl logs` on fluentbit pods.
This is a good way to experiment with configuration.
Switch to [Format](https://docs.fluentbit.io/manual/pipeline/outputs/standard-output#configuration-parameters) `msgpack` to also see the "tag" (helpful when developing your pipeline).

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/kafka/fluent-bit-ds.yaml
```
## Logs ingested to Loki

#### Fluent Bit to Elasticsearch on Minikube
This repository serves as example of Kubernetes yaml for a log processing stack,
not as example of [how](https://docs.fluentbit.io/manual/concepts/data-pipeline) Fluent-bit can process, refine and forward log entries.

If you are using Minikube for testing purposes, use the following alternative DaemonSet manifest:

```
$ kubectl create -f https://raw.githubusercontent.com/fluent/fluent-bit-kubernetes-logging/master/output/elasticsearch/fluent-bit-ds-minikube.yaml
```
Use the [loki](./loki) base to replace Stdout with forwarding to a standalone Loki instance. Loki can do some processing at [query time](https://grafana.com/docs/loki/latest/logql/) which helps keep this repo light on pipeline config.

## Details
The [loki-plugin](./loki-plugin) base uses an out-of-tree plugin with `DropSingleKey`
so that the log records forwarded are the actual logged lines from pods,
but still queryable on labels like `pod` and `container`.

The default configuration of Fluent Bit makes sure of the following:
See the [lokitest](./loki/test/lokitest-job.yaml) Job for some examples of how to consume logs through Loki.

- Consume all containers logs from the running Node.
- The [Tail input plugin](http://fluentbit.io/documentation/0.12/input/tail.html) will not append more than __5MB__ into the engine until they are flushed to the Elasticsearch backend. This limit aims to provide a workaround for [backpressure](http://fluentbit.io/documentation/0.13/configuration/backpressure.html) scenarios.
- The Kubernetes filter will enrich the logs with Kubernetes metadata, specifically _labels_ and _annotations_. The filter only goes to the API Server when it cannot find the cached info, otherwise it uses the cache.
- The default backend in the configuration is Elasticsearch set by the [Elasticsearch Output Plugin](http://fluentbit.io/documentation/0.13/output/elasticsearch.html). It uses the Logstash format to ingest the logs. If you need a different Index and Type, please refer to the plugin option and do your own adjustments.
- There is an option called __Retry_Limit__ set to False that means if Fluent Bit cannot flush the records to Elasticsearch it will re-try indefinitely until it succeeds.
The loki folders also serve as [example](./loki/kustomization.yaml) of how to use Kustomize to override selected parts of the `base`'s *.conf.

## Get in touch with us!

Expand Down
11 changes: 11 additions & 0 deletions base/filter-kubernetes.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[FILTER]
Name kubernetes
Match kube.*
Kube_Tag_Prefix kube.
Regex_Parser kube-tag
# Merge_Log On
# Merge_Log_Key log_processed
K8S-Logging.Parser On
K8S-Logging.Exclude On
Annotations Off
13 changes: 13 additions & 0 deletions base/fluent-bit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[SERVICE]
Flush 1
Log_Level ${LOG_LEVEL}
Daemon off
Parsers_File parser-cri.conf
Parsers_File parsers.conf
HTTP_Server On
HTTP_Listen 0.0.0.0
HTTP_Port 2020

@INCLUDE input-kubernetes.conf
@INCLUDE filter-kubernetes.conf
@INCLUDE outputs.conf
73 changes: 73 additions & 0 deletions base/fluentbit-daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentbit
labels:
app.kubernetes.io/name: fluentbit
spec:
selector:
matchLabels:
app.kubernetes.io/name: fluentbit
template:
metadata:
labels:
app.kubernetes.io/name: fluentbit
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "2020"
prometheus.io/path: /api/v1/metrics/prometheus
spec:
serviceAccountName: fluentbit
terminationGracePeriodSeconds: 25
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
containers:
- name: fluentbit
image: docker.io/fluent/fluent-bit
command:
- /fluent-bit/bin/fluent-bit
- -c
- /fluent-bit/etc/fluent-bit.conf
env:
- name: LOG_LEVEL
value: debug
- name: MEM_BUF_LIMIT
value: 5MB
ports:
- name: http
containerPort: 2020
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /api/v1/health
port: http
volumeMounts:
- name: varlogpods
mountPath: /var/log/pods
readOnly: true
- name: db
mountPath: /var/run/fluentbit
- name: config
mountPath: /fluent-bit/etc
# - mountPath: /etc/machine-id
# name: etcmachineid
# readOnly: true
volumes:
- name: varlogpods
hostPath:
path: /var/log/pods
- name: db
hostPath:
path: /var/run/fluentbit
# - name: etcmachineid
# hostPath:
# path: /etc/machine-id
# type: File
- name: config
configMap:
name: fluentbit
11 changes: 11 additions & 0 deletions base/input-kubernetes.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[INPUT]
Name tail
DB /var/run/fluentbit/tail-positions.db
Mem_Buf_Limit ${MEM_BUF_LIMIT}
Skip_Long_Lines On
DB.locking true
Path /var/log/pods/*/*/*.log
Exclude_Path /var/log/pods/*/fluentbit/*.log
Parser cri
Tag kube.<pod_id>.<namespace_name>.<pod_name>.<container_name>
Tag_Regex /var/log/pods/(?<namespace_name>[^_/]+)_(?<pod_name>[^_/]+)_(?<pod_id>[^_/]+)/(?<container_name>[^/]+)/.*
25 changes: 25 additions & 0 deletions base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: logging

images:
- name: docker.io/fluent/fluent-bit
newTag: 1.8.3@sha256:10ea2709cef6e7059d980b4969d5f9d753ef97278a817c214cbe9120b1152082

commonLabels:
app.kubernetes.io/name: fluentbit

resources:
- ../rbac
- fluentbit-daemonset.yaml

configMapGenerator:
- name: fluentbit
files:
- fluent-bit.conf
- parser-cri.conf
- input-kubernetes.conf
- filter-kubernetes.conf
- parsers.conf
- outputs.conf
6 changes: 6 additions & 0 deletions base/outputs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[OUTPUT]
Name stdout
# Switch to format msgpack to see the tags
Format json_lines
json_date_key t
json_date_format iso8601
12 changes: 12 additions & 0 deletions base/parser-cri.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[PARSER]
Name cri
Format regex
Regex ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>[^ ]*) (?<log>.*)$
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%L%z

[PARSER]
Name kube-tag
Format regex
Regex ^(?<pod_id>[^.]+)\.(?<namespace_name>[^.]+)\.(?<pod_name>[^.]+)\.(?<container_name>[^.]+)$
Empty file added base/parsers.conf
Empty file.
86 changes: 0 additions & 86 deletions fluent-bit-config-kafka-rest.yml

This file was deleted.

Loading