A developer may want to provide additional features for their application, such as sending logs to an external endpoint.
Developers can write these features directly into an application’s container, or they can create a “sidecar” container that does some of this work.
One common example of a sidecar feature may be to include a FluentBit container in your pod that sends log data to an Elastic Search database. This can be used for customizable metrics monitoring, or system debugging.
Workflow for including FluentBit sidecar container:
Path
to your container’s log directoryCopy the namespace helper function into your _helpers.tpl
file.
{{- define "namespace" -}}
{{- .Release.Namespace | trimPrefix "slate-vo-" | printf " %s" -}}
{{- end -}}
Include the FluentBit container in your deployment, and mount a shared volume around the log files in your host container, and mount your ConfigMap. For example:
...
containers:
- name: fluent-bit
image: fluent/fluent-bit:0.13.4
imagePullPolicy: IfNotPresent
volumeMounts:
- name: {{ template "[chart].fullname" . }}-fluent-bit-config
mountPath: /fluent-bit/etc/
- name: varlog
mountPath: /var/log
...
volumes:
- name: {{ template "[chart].fullname" . }}-fluent-bit-config
configMap:
name: {{ template "[chart].fullname" . }}-fluent-bit-config
- name: varlog
emptyDir: {}
...
where varlog
is mounted to FluentBit and to your container’s log directory.