Skip to main content

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:

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: {}.

furyctl.yaml
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.

  1. Write the output in a file, for example manifests/external-loki.yaml next to furyctl.yaml:

    manifests/external-loki.yaml
    apiVersion: logging.banzaicloud.io/v1beta1
    kind: ClusterOutput
    metadata:
    name: external-loki
    # The control namespace of Logging Operator in SD
    namespace: logging
    spec:
    loki:
    url: https://loki.example.com
    configure_kubernetes_labels: true
    extra_labels:
    k8s_cluster: my-cluster
    buffer:
    timekey: 1m
    timekey_wait: 10s
    timekey_use_utc: true
  2. Write the patch for the kubernetes ClusterFlow in a file, for example patches/clusterflow-kubernetes.yaml:

    patches/clusterflow-kubernetes.yaml
    - op: add
    path: /spec/globalOutputRefs/-
    value: external-loki

    The patch adds external-loki to the outputs of the ClusterFlow, after the SD output. The Logging Operator sends each log line to all the outputs of the Flow.

  3. Add the output and the patch to furyctl.yaml:

    furyctl.yaml
    spec:
    distribution:
    customResources:
    - ./manifests/external-loki.yaml
    customPatches:
    patches:
    - target:
    group: logging.banzaicloud.io
    version: v1beta1
    kind: ClusterFlow
    name: kubernetes
    path: ./patches/clusterflow-kubernetes.yaml

    For more information, see Keep the patches in separate files.

  4. Apply the configuration:

    furyctl apply --phase distribution
  5. Make sure that the Logging Operator accepted the output and the ClusterFlow:

    kubectl -n logging get clusteroutput external-loki
    kubectl -n logging get clusterflow kubernetes

    The ACTIVE column shows true and the PROBLEMS column 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:

patches/flow-audit.yaml
- op: add
path: /spec/globalOutputRefs
value:
- external-loki
furyctl.yaml
spec:
distribution:
customPatches:
patches:
- target:
group: logging.banzaicloud.io
version: v1beta1
kind: Flow
name: audit
namespace: logging
path: ./patches/flow-audit.yaml
note

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.