Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Fluent Bit #2723

Merged
merged 11 commits into from
Aug 24, 2020
Merged
1 change: 1 addition & 0 deletions buildchain/buildchain/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def _operator_image(name: str, **kwargs: Any) -> targets.OperatorImage:
],
constants.GRAFANA_REPOSITORY: [
'loki',
'fluent-bit-plugin-loki',
],
constants.INGRESS_REPOSITORY: [
'nginx-ingress-controller',
Expand Down
4 changes: 4 additions & 0 deletions buildchain/buildchain/salt_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def _get_parts(self) -> Iterator[str]:

Path('salt/metalk8s/addons/logging/deployed/init.sls'),
Path('salt/metalk8s/addons/logging/deployed/namespace.sls'),
Path('salt/metalk8s/addons/logging/fluent-bit/deployed/chart.sls'),
Path('salt/metalk8s/addons/logging/fluent-bit/deployed/configmap.sls'),
Path('salt/metalk8s/addons/logging/fluent-bit/deployed/init.sls'),
Path('salt/metalk8s/addons/logging/loki/config/loki.yaml'),
Path('salt/metalk8s/addons/logging/loki/deployed/chart.sls'),
Path('salt/metalk8s/addons/logging/loki/deployed/datasource.sls'),
Expand All @@ -279,6 +282,7 @@ def _get_parts(self) -> Iterator[str]:
'loki-configuration-secret.sls'),
Path('salt/metalk8s/addons/logging/loki/deployed/',
'service-configuration.sls'),
Path('salt/metalk8s/addons/logging/loki/deployed/services.sls'),
Path('salt/metalk8s/addons/logging/loki/deployed/storageclass.sls'),

Path('salt/metalk8s/addons/prometheus-adapter/deployed/chart.sls'),
Expand Down
5 changes: 5 additions & 0 deletions buildchain/buildchain/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def _version_prefix(version: str, prefix: str = 'v') -> str:
version='1.5.0',
digest='sha256:922b3f412fdd9a8fb01115b6aebf5dac162647ce1c5ee3637ce1e2cff69e097b',
),
Image(
name='fluent-bit-plugin-loki',
version='1.5.0-amd64',
digest='sha256:2d0e9b06a2bf894fa91300fa38a185ac44a7bedcb8a2c63b8f6077e5cf80fc4d',
),
)

CONTAINER_IMAGES_MAP = {image.name: image for image in CONTAINER_IMAGES}
Expand Down
129 changes: 129 additions & 0 deletions charts/fluent-bit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
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)'
tag: 1.5.0-amd64
pullPolicy: IfNotPresent

nameOverride: fluent-bit

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

## Pod Labels
podLabels: {}

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
operator: Exists
- key: node-role.kubernetes.io/etcd
effect: NoSchedule
operator: Exists
- key: node-role.kubernetes.io/infra
effect: NoSchedule
operator: Exists
- key: node-role.kubernetes.io/master
effect: NoSchedule
operator: Exists

# Extra volumes to scrape logs from
volumes:
- name: varlog
hostPath:
path: /var/log
# /run/log is used to fetch journal logs
- name: runlog
hostPath:
path: /run/log

volumeMounts:
- name: varlog
mountPath: /var/log
readOnly: true
- name: runlog
mountPath: /run/log
readOnly: true

serviceMonitor:
enabled: true
interval: ""
additionalLabels:
release: prometheus-operator
annotations: {}
# scrapeTimeout: 10s
22 changes: 22 additions & 0 deletions charts/fluent-bit/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions charts/fluent-bit/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
appVersion: v1.5.0
description: Uses fluent-bit Loki go plugin for gathering logs and sending them to
Loki
engine: gotpl
home: https://grafana.com/loki
icon: https://github.com/grafana/loki/raw/master/docs/logo.png
kubeVersion: ^1.10.0-0
maintainers:
- email: [email protected]
name: Loki Maintainers
name: fluent-bit
sources:
- https://github.com/grafana/loki
version: 0.1.5
113 changes: 113 additions & 0 deletions charts/fluent-bit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Fluent Bit Loki 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.

## 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 loki https://grafana.github.io/loki/charts
helm upgrade --install my-release loki/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 configure the chart to send to [Grafana Cloud](https://grafana.com/products/cloud) use:

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

> **Tip**: List all releases using `helm list`

To install a custom tag use the following command:

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

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

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

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

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`.

## Uninstalling the Chart

To uninstall/delete the `my-release` deployment:

```bash
helm delete my-release
```

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.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` |


[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
3 changes: 3 additions & 0 deletions charts/fluent-bit/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Verify the application is working by running these commands:
kubectl --namespace {{ .Release.Namespace }} port-forward daemonset/{{ include "fluent-bit-loki.fullname" . }} {{ .Values.config.port }}
curl http://127.0.0.1:{{ .Values.config.port }}/api/v1/metrics/prometheus
66 changes: 66 additions & 0 deletions charts/fluent-bit/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "fluent-bit-loki.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "fluent-bit-loki.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "fluent-bit-loki.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "fluent-bit-loki.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "fluent-bit-loki.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
The service name to connect to Loki. Defaults to the same logic as "loki.fullname"
*/}}
{{- define "loki.serviceName" -}}
{{- if .Values.loki.serviceName -}}
{{- .Values.loki.serviceName -}}
{{- else if .Values.loki.fullnameOverride -}}
{{- .Values.loki.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default "loki" .Values.loki.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "helm-toolkit.utils.joinListWithComma" -}}
{{- $local := dict "first" true -}}
{{- range $k, $v := . -}}{{- if not $local.first -}},{{- end -}}{{- $v -}}{{- $_ := set $local "first" false -}}{{- end -}}
{{- end -}}
Loading