Skip to content

Commit

Permalink
chart,salt,build: Migrate to fluent-bit fluent chart
Browse files Browse the repository at this point in the history
Migrate from grafana fluent-bit deprecated helm chart to the fluent-bit
helm chart from fluent:

```
rm -rf charts/fluent-bit
helm repo add fluent https://fluent.github.io/helm-charts
helm repo update
helm fetch -d charts --untar fluent/fluent-bit
```

Change image from `fluent-bit-loki-plugin` from grafana repository to
1.8.12 `fluent-bit` from fluent repository as Loki output plugin is
built-in.

Migrate fluent-bit option file to work with the new fluent-bit helm
template.

Rewrite fluent-bit output from config as it's not exactly the same
between `grafana-loki` and `loki`.

We also enable HTTP_Server back as it seems to work properly with this
version.

Render chart to salt state using:

```
./charts/render.py fluent-bit --namespace metalk8s-logging \
  charts/fluent-bit.yaml charts/fluent-bit/ \
  > salt/metalk8s/addons/logging/fluent-bit/deployed/chart.sls
```

Fixes: #3435
  • Loading branch information
TeddyAndrieux committed Feb 21, 2022
1 parent cd5e889 commit d1974fe
Show file tree
Hide file tree
Showing 39 changed files with 2,560 additions and 745 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
[2.4.2](https://github.com/grafana/loki/releases/tag/v2.4.2)
(PR[#3698](https://github.com/scality/metalk8s/pull/3698))

- Migrate from grafana fluent-bit deprecated chart to fluent-bit fluent chart
version [0.19.19](https://github.com/fluent/helm-charts/releases/tag/fluent-bit-0.19.19)
The fluent-bit-plugin-loki image has been changed accordingly to fluent-bit
version [1.8.12](https://github.com/fluent/fluent-bit/releases/tag/v1.8.12)
(PR[#3709](https://github.com/scality/metalk8s/pull/3709))

- Bump MetalLB chart version to
[2.6.2](https://artifacthub.io/packages/helm/bitnami/metallb/2.6.2)
The following images have also been bumped accordingly:
Expand Down
1 change: 1 addition & 0 deletions buildchain/buildchain/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
COREDNS_REPOSITORY: str = "k8s.gcr.io/coredns"
DEX_REPOSITORY: str = "ghcr.io/dexidp"
DOCKER_REPOSITORY: str = "docker.io/library"
FLUENT_REPOSITORY: str = "docker.io/fluent"
GOOGLE_REPOSITORY: str = "k8s.gcr.io"
GRAFANA_REPOSITORY: str = "docker.io/grafana"
INGRESS_REPOSITORY: str = "k8s.gcr.io/ingress-nginx"
Expand Down
4 changes: 3 additions & 1 deletion buildchain/buildchain/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def _local_image(name: str, **kwargs: Any) -> targets.LocalImage:
constants.DOCKER_REPOSITORY: [
"nginx",
],
constants.FLUENT_REPOSITORY: [
"fluent-bit",
],
constants.GOOGLE_REPOSITORY: [
"etcd",
"kube-apiserver",
Expand All @@ -186,7 +189,6 @@ def _local_image(name: str, **kwargs: Any) -> targets.LocalImage:
constants.GRAFANA_REPOSITORY: [
"grafana",
"loki",
"fluent-bit-plugin-loki",
],
constants.INGRESS_REPOSITORY: [
"nginx-ingress-controller",
Expand Down
6 changes: 3 additions & 3 deletions buildchain/buildchain/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ def _version_prefix(version: str, prefix: str = "v") -> str:
digest="sha256:b3af8ead67d7e80fec05029f783784df897e92b6dba31fe4b33ab4ea3e989573",
),
Image(
name="fluent-bit-plugin-loki",
version="2.1.0-amd64",
digest="sha256:bedd17176ced6106404606d31f6d6bfa56b10d769074c0b624fb0bc470b081c2",
name="fluent-bit",
version="1.8.12",
digest="sha256:35de7f8e4cf845c060d3feb09e19254177993537dfb7b8a06a8ba5748e6b8551",
),
)

Expand Down
95 changes: 12 additions & 83 deletions charts/fluent-bit.yaml
Original file line number Diff line number Diff line change
@@ -1,92 +1,21 @@
---
loki:
serviceName: loki # Defaults to "${RELEASE}-loki" if not set
servicePort: 3100
serviceScheme: http
servicePath: /api/prom/push
# user: user
# password: pass
# the whole `config` block is not used as it does not allow us to add
# additional inputs. To workaround this, we're deploying our own
# ConfigMap instead.
# config:
# port: 2020
# tenantID: '""'
# batchWait: 1
# batchSize: 10240
# loglevel: warn
# lineFormat: json
# k8sLoggingParser: "Off"
# removeKeys:
# - kubernetes
# - stream
# autoKubernetesLabels: false
# labels: '{job="fluent-bit"}'
# labelMap:
# kubernetes:
# namespace_name: namespace
# labels:
# app: app
# release: release
# host: node
# container_name: container
# pod_name: instance
# stream: stream
# parsers: # Allow to define custom parsers. The key here is the same as the one in the [PARSER] section of parsers.conf file.
# - Name: json
# Format: json
# Time_Key: time
# Time_Format: "%d/%b/%Y:%H:%M:%S %z"

# extraOutputs: # Allow to define extra outputs in addition to the one automatically created
# - Name: stdout
# Format: json
# json_date_format: time

affinity: {}

annotations: {}

deploymentStrategy: RollingUpdate

image:
repository: '__image__(fluent-bit-plugin-loki)'
repository: '__image__(fluent-bit)'
pullPolicy: IfNotPresent

nameOverride: fluent-bit

## Node labels for pod assignment
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
nodeSelector: {}

## Pod Labels
podLabels: {}
existingConfigMap: fluent-bit

podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "2020"
prometheus.io/path: /api/v1/metrics/prometheus

## Assign a PriorityClassName to pods if set
# priorityClassName:

rbac:
create: true
pspEnabled: true

resources:
limits:
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi

serviceAccount:
create: true
name:

## Tolerations for pod assignment
## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
tolerations:
- key: node-role.kubernetes.io/bootstrap
effect: NoSchedule
Expand All @@ -102,7 +31,11 @@ tolerations:
operator: Exists

# Extra volumes to scrape logs from
volumes:
daemonSetVolumes:
# /run/fluent-bit is used for fluent-bit DB
- name: run
hostPath:
path: /run/fluent-bit
- name: varlog
hostPath:
path: /var/log
Expand All @@ -111,7 +44,9 @@ volumes:
hostPath:
path: /run/log

volumeMounts:
daemonSetVolumeMounts:
- name: run
mountPath: /run/fluent-bit
- name: varlog
mountPath: /var/log
readOnly: true
Expand All @@ -120,12 +55,6 @@ volumeMounts:
readOnly: true

serviceMonitor:
# Disabled for the moment as http_server does not work with current
# fluent-bit version + kubernetes version
# See: https://github.com/fluent/fluent-bit/issues/4063
enabled: false
interval: ""
additionalLabels:
enabled: true
selector:
metalk8s.scality.com/monitor: ''
annotations: {}
# scrapeTimeout: 10s
1 change: 1 addition & 0 deletions charts/fluent-bit/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
Expand Down
32 changes: 23 additions & 9 deletions charts/fluent-bit/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
annotations:
artifacthub.io/changes: |
- kind: changed
description: "Update fluent-bit image to 1.8.12."
apiVersion: v1
appVersion: v2.1.0
description: Uses fluent-bit Loki go plugin for gathering logs and sending them to Loki
home: https://grafana.com/loki
icon: https://raw.githubusercontent.com/grafana/loki/master/docs/sources/logo.png
kubeVersion: ^1.10.0-0
appVersion: 1.8.12
description: Fast and lightweight log processor and forwarder or Linux, OSX and BSD
family operating systems.
home: https://fluentbit.io/
icon: https://fluentbit.io/assets/img/logo1-default.png
keywords:
- logging
- fluent-bit
- fluentd
maintainers:
- email: [email protected]
name: Loki Maintainers
- email: [email protected]
name: edsiper
- email: [email protected]
name: naseemkullah
- email: [email protected]
name: Towmeykaw
- email: [email protected]
name: stevehipwell
name: fluent-bit
sources:
- https://github.com/grafana/loki
version: 2.2.0
- https://github.com/fluent/fluent-bit/
version: 0.19.19
143 changes: 38 additions & 105 deletions charts/fluent-bit/README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,57 @@
# Fluent Bit Loki chart
# Fluent Bit Helm chart

This chart install the Fluent Bit application to ship logs to Loki. It defines daemonset on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.
[Fluent Bit](https://fluentbit.io) is a fast and lightweight log processor and forwarder or Linux, OSX and BSD family operating systems.

## Get Repo Info
## Installation

```console
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
```

_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._

## Installing the Chart

> If you don't have `Helm` installed locally, or `Tiller` installed in your Kubernetes cluster, read the [Using Helm](https://docs.helm.sh/using_helm/) documentation to get started.
To install the chart with the release name `my-release` using our helm repository:

```bash
helm repo add grafana https://grafana.github.io/helm-charts
helm upgrade --install my-release grafana/fluent-bit \
--set loki.serviceName=loki.default.svc.cluster.local
```

If you deploy Loki with a custom namespace or service name, you must change the value above for `loki.serviceName` to the appropriate value.

The command deploys Fluent Bit on the Kubernetes cluster with the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
To add the `fluent` helm repo, run:

To configure the chart to send to [Grafana Cloud](https://grafana.com/products/cloud) use:

```bash
helm upgrade --install my-release grafana/fluent-bit \
--set loki.serviceName=logs-us-west1.grafana.net,loki.servicePort=80,loki.serviceScheme=https \
--set loki.user=2830,loki.password=1234
```sh
helm repo add fluent https://fluent.github.io/helm-charts
```

> **Tip**: List all releases using `helm list`
To install a custom tag use the following command:
To install a release named `fluent-bit`, run:

```bash
helm upgrade --install my-release grafana/fluent-bit \
--set image.tag=<custom tag>
```sh
helm install fluent-bit fluent/fluent-bit
```

The full list of available tags on [docker hub](https://cloud.docker.com/u/grafana/repository/docker/grafana/fluent-bit-plugin-loki).
## Chart values

Alternatively you can install the full [Loki stack](../loki-stack) (Loki + Fluent Bit) using:

```bash
helm upgrade --install my-release grafana/loki-stack \
--set fluent-bit.enabled=true,promtail.enabled=false
```sh
helm show values fluent/fluent-bit
```

This will automatically configured the `loki.serviceName` configuration field to the newly created Loki instance.

## RBAC

By default, `rbac.create` is set to true. This enable RBAC support in Fluent Bit and must be true if RBAC is enabled in your cluster.

The chart will take care of creating the required service accounts and roles for Fluent Bit.

If you have RBAC disabled, or to put it another way, ABAC enabled, you should set this value to `false`.
## Using Lua scripts
Fluent Bit allows us to build filter to modify the incoming records using custom [Lua scripts.](https://docs.fluentbit.io/manual/pipeline/filters/lua)

## Uninstalling the Chart
### How to use Lua scripts with this Chart

To uninstall/delete the `my-release` deployment:
First, you should add your Lua scripts to `luaScripts` in values.yaml, for example:

```bash
helm delete my-release
```yaml
luaScripts:
filter_example.lua: |
function filter_name(tag, timestamp, record)
-- put your lua code here.
end
```
The command removes all the Kubernetes components associated with the chart and deletes the release.

## Configuration

The following tables lists the configurable parameters of the Fluent Bit chart and their default values.

For more details, read the [Fluent Bit documentation](../../../cmd/fluent-bit/README.md)

| Parameter | Description | Default |
|--------------------------|----------------------------------------------------------------------------------------------------|----------------------------------|
| `loki.serviceName` | The address of the Loki service. | `"${RELEASE}-loki"` |
| `loki.servicePort` | The port of the Loki service. | `3100` |
| `loki.serviceScheme` | The scheme of the Loki service. | `http` |
| `loki.user` | The http basic auth username to access the Loki service. | |
| `loki.password` | The http basic auth password to access the Loki service. | |
| `config.port` | the Fluent Bit port to listen. (This is mainly used to serve metrics) | `2020` |
| `config.tenantID` | The tenantID used by default to push logs to Loki | `''` |
| `config.batchWait` | Time to wait before send a log batch to Loki, full or not. (unit: secs) | `1` |
| `config.batchSize` | Log batch size to send a log batch to Loki. (unit: bytes) | `10240` (10KiB) |
| `config.loglevel` | the Fluent Bit log level (debug,info,warn,error). | `warn` |
| `config.lineFormat` | The line format to use to send a record (json/key_value) | `json` |
| `config.k8sLoggingParser`| Allow Kubernetes Pods to suggest a pre-defined Parser. See [Official Fluent Bit documentation](https://docs.fluentbit.io/manual/filter/kubernetes#kubernetes-annotations). | `Off` |
| `config.k8sLoggingExclude`| Allow Kubernetes Pods to exclude their logs from the log processor. See [Official Fluent Bit documentation](https://docs.fluentbit.io/manual/pipeline/filters/kubernetes) | `Off`
| `config.memBufLimit` | Override the default Mem_Buf_Limit [Official Fluent Bit documentation](https://docs.fluentbit.io/manual/administration/backpressure#mem_buf_limit) | `5MB`
| `config.removeKeys` | The list of key to remove from each record | `[removeKeys,stream]` |
| `config.labels` | A set of labels to send for every log | `'{job="fluent-bit"}'` |
| `config.autoKubernetesLabels` | If set to true, it will add all Kubernetes labels to Loki labels | `false` |
| `config.labelMap` | Mapping of labels from a record. See [Fluent Bit documentation](../../../cmd/fluent-bit/README.md) | |
| `config.parsers` | Definition of extras fluent bit parsers. See [Official Fluent Bit documentation](https://docs.fluentbit.io/manual/filter/parser). The format is a sequence of mappings where each key is the same as the one in the [PARSER] section of parsers.conf file | `[]` |
| `config.extraOutputs` | Definition of extras fluent bit outputs. See [Official Fluent Bit documentation](https://docs.fluentbit.io/manual/pipeline/outputs/). The format is a sequence of mappings where each key is the same as the one in the [OUTPUT] | `[]` |
| `affinity` | [affinity][affinity] settings for pod assignment | `{}` |
| `annotations` | Annotations to add to Kubernetes resources. | `{}` |
| `deploymentStrategy` | The deployment strategy to use with the daemonset | `RollingUpdate` |
| `image.repository` | The Fluent Bit docker image repository | `grafana/fluent-bit-plugin-loki` |
| `image.tag` | The Fluent Bit docker image tag | `0.1` |
| `image.pullPolicy` | The Fluent Bit docker image pull policy | `IfNotPresent` |
| `nodeSelector` | Fluent Bit [node labels][nodeSelector] for pod assignment | `{}` |
| `podLabels` | additional Fluent Bit pod labels | `{}` |
| `podAnnotations` | additional Fluent Bit pod annotations | `Prometheus discovery` |
| `rbac.create` | Activate support for RBAC | `true` |
| `resources` | Resource requests/limit | |
| `tolerations` | [Toleration][toleration] labels for pod assignment | `no schedule on master nodes` |
| `volumes` | [Volume]([volumes]) to mount | `host containers log` |
| `volumeMounts` | Volume mount mapping | |
| `serviceMonitor.enabled` | Create a [Prometheus Operator](operator) serviceMonitor resource for Fluent Bit | `false` |
After that, the Lua scripts will be ready to be used as filters. So next step is to add your Fluent bit [filter](https://docs.fluentbit.io/manual/concepts/data-pipeline/filter) to `config.filters` in values.yaml, for example:

```yaml
config:
filters: |
[FILTER]
Name lua
Match <your-tag>
script /fluent-bit/scripts/filter_example.lua
call filter_name
```
Under the hood, the chart will:
- Create a configmap using `luaScripts`.
- Add a volumeMounts for each Lua scripts using the path `/fluent-bit/scripts/<script>`.
- Add the Lua script's configmap as volume to the pod.

[toleration]: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
[nodeSelector]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
[affinity]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
[volumes]: https://kubernetes.io/docs/concepts/storage/volumes/
[operator]: https://github.com/coreos/prometheus-operator
### Note
Remember to set the `script` attribute in the filter using `/fluent-bit/scripts/`, otherwise the file will not be found by fluent bit.
1 change: 1 addition & 0 deletions charts/fluent-bit/ci/ci-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logLevel: debug
Loading

0 comments on commit d1974fe

Please sign in to comment.