Send logs to an external collector
This page tells you how to send the logs of an SD cluster to a log collector outside the cluster. Examples of collectors are a central Loki, a syslog server and an S3 bucket.
There are two methods:
- Replace the in-cluster storage: SD does not install OpenSearch or Loki, and sends all the logs to your collectors.
- Send a copy of some logs: SD keeps the in-cluster storage, and also sends a copy of the logs of some Flows to your collector.
Both methods use Logging Operator outputs. For the Flows of SD and the logs that each one collects, see Log collection.
Replace the in-cluster storage
Set the Logging module type to customOutputs, and give an output for each Flow of SD in customOutputs. The schema requires all the fields of customOutputs. To discard the logs of a Flow, use nullout: {}.
spec:
distribution:
modules:
logging:
type: customOutputs
customOutputs:
kubernetes: |-
loki:
url: https://loki.example.com
configure_kubernetes_labels: true
buffer:
timekey: 1m
timekey_wait: 10s
timekey_use_utc: true
audit: |-
nullout: {}
events: |-
nullout: {}
infra: |-
nullout: {}
ingressHaproxy: |-
nullout: {}
ingressNginx: |-
nullout: {}
systemdCommon: |-
nullout: {}
systemdEtcd: |-
nullout: {}
errors: |-
nullout: {}
Each value is the spec of a Logging Operator output. For a longer example, see Log storage › Remote storage.
Send a copy of some logs
In this example, SD keeps OpenSearch or Loki in the cluster, and sends a copy of the application logs to an external Loki. The application logs come from the kubernetes ClusterFlow.
-
Write the output in a file, for example
manifests/external-loki.yamlnext tofuryctl.yaml:manifests/external-loki.yamlapiVersion: logging.banzaicloud.io/v1beta1kind: ClusterOutputmetadata:name: external-loki# The control namespace of Logging Operator in SDnamespace: loggingspec:loki:url: https://loki.example.comconfigure_kubernetes_labels: trueextra_labels:k8s_cluster: my-clusterbuffer:timekey: 1mtimekey_wait: 10stimekey_use_utc: true -
Write the patch for the
kubernetesClusterFlow in a file, for examplepatches/clusterflow-kubernetes.yaml:patches/clusterflow-kubernetes.yaml- op: addpath: /spec/globalOutputRefs/-value: external-lokiThe patch adds
external-lokito the outputs of the ClusterFlow, after the SD output. The Logging Operator sends each log line to all the outputs of the Flow. -
Add the output and the patch to
furyctl.yaml:furyctl.yamlspec:distribution:customResources:- ./manifests/external-loki.yamlcustomPatches:patches:- target:group: logging.banzaicloud.ioversion: v1beta1kind: ClusterFlowname: kubernetespath: ./patches/clusterflow-kubernetes.yamlFor more information, see Keep the patches in separate files.
-
Apply the configuration:
furyctl apply --phase distribution -
Make sure that the Logging Operator accepted the output and the ClusterFlow:
kubectl -n logging get clusteroutput external-lokikubectl -n logging get clusterflow kubernetesThe
ACTIVEcolumn showstrueand thePROBLEMScolumn is empty.
To send a copy of other logs, patch their Flow. The infra and kubernetes Flows are ClusterFlows, with a globalOutputRefs list. The other Flows of SD are namespaced Flows without this list, for example the audit Flow in the logging namespace. For a namespaced Flow, the patch adds the list:
- op: add
path: /spec/globalOutputRefs
value:
- external-loki
spec:
distribution:
customPatches:
patches:
- target:
group: logging.banzaicloud.io
version: v1beta1
kind: Flow
name: audit
namespace: logging
path: ./patches/flow-audit.yaml
The firewall between the cluster and the collector must allow the connections from the nodes that run fluentd, in the logging namespace. The network policies of SD do not block them: fluentd can connect to all the addresses.