How to test rancher-logging Flows and Outputs with local file output
Article Number: 000021317
Environment
- A Rancher v2.5+ managed Kubernetes clusters
- rancher-logging installed in the cluster
Situation
When configuring rancher-logging on a cluster, it may be necessary to troubleshoot Flows and Outputs. This guide provides a way to test these without any third-party tools involved (e.g. an external logging destination such as Elasticsearch).
Resolution
- The first step will be to create an Output on the cluster-logging-system namespace. You can do so by exploring the cluster within the Rancher UI, navigating to Logging > Outputs in the resources menu on the left side, and then clicking Create (alternatively, you can apply the manifest via the kubectl CLI). The following example manifest will create a basic Output that you can customize later. It will send the resulting logs to the /tmp/logs/ folder on the FluentD pod (rancher-logging-root-fluentd-0) in the cluster-logging-system Namespace:
apiVersion: logging.banzaicloud.io/v1beta1
kind: Output
metadata:
name: test-output
namespace: cattle-logging-system
spec:
file:
path: /tmp/logs/${tag}/%Y/%m/%d/%H.%M
buffer:
timekey: 1m
timekey_wait: 10s
timekey_use_utc: true
apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
name: test-flow
namespace: cattle-logging-system
spec:
localOutputRefs:
- test-output
match:
- select:
labels:
logging-test: 'true'
apiVersion: v1
kind: Pod
metadata:
name: test-logging-pod
namespace: cattle-logging-system
labels:
logging-test: "true"
spec:
containers:
- name: sak
image: rancherlabs/swiss-army-knife:latest
$ kubectl -n cattle-logging-system exec -it test-logging-pod -- /bin/bash
# echo 'Hello World from Rancher Logging!' > /proc/1/fd/1
$ ls -lrt /tmp/logs total 4 drwxr-xr-x 3 fluent fluent 4096 Feb 28 15:06 kubernetes.var.log.containers.test-logging-pod_cattle-logging-system_sak-8611b0ee3869dc245a4921aac63242901b104f77c86c7d58a32caafafe59aaaa.log
$ cat 15.05_0.log 2024-02-28T15:05:50+00:00 kubernetes.var.log.containers.test-logging-pod_cattle-logging-system_sak-8611b0ee3869dc245a4921aac63242901b104f77c86c7d58a32caafafe59aaaa.log {"log":"Hello World from Rancher Logging!\n","stream":"stdout","time":"2024-02-28T15:05:50.766535534Z","kubernetes":{"pod_name":"test-logging-pod","namespace_name":"cattle-logging-system","pod_id":"1d16a19e-f565-447b-b9f0-39bdf559eaf6","labels"..... ``` 7. You can now freely change your Output and Flow configuration to test and troubleshoot configurations, filters and parsers etc. The results will appear in the /tmp/logs/ folder of the Fluentd pod.