Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions receiver/journaldreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ The user running the collector must have enough permissions to access the journa

When running in a containerized environment, differences in the systemd version running on the host and on the container may prevent access to logs due to different features and configurations (e.g. zstd compression, keyed hash etc).

### Docker
### Docker & Kubernetes

When running otelcol in a container, note that:

Expand All @@ -192,6 +192,8 @@ When running otelcol in a container, note that:

Please note that *the official otelcol images do not contain the journald binary*; you will need to create your custom image or find one that does.

There is a simple example with a step-by-step, including a `Dockerfile` in [`examples/container`](examples/container/README.md).

### Linux packaging

When installing otelcol as a linux package, you will most likely need to add the `otelcol-contrib` or `otel` user to the `systemd-journal` group. The exact user and group might vary depending on your package and linux distribution of choice.
Expand All @@ -203,7 +205,3 @@ sudo su -s /bin/bash -c 'journalctl --lines 5' otelcol-contrib
```

if the permissions are set correctly you will see some logs, otherwise a clear error message.

### Kubernetes

See the instructions for [Docker](#Docker) and adapt according to your Kubernetes distribution and node OS.
17 changes: 17 additions & 0 deletions receiver/journaldreceiver/examples/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM debian:13-slim

ARG OTEL_COL_VERSION=0.136.0

WORKDIR /opt

RUN apt update && \
apt install -y systemd wget && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN wget "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_COL_VERSION}/otelcol-contrib_${OTEL_COL_VERSION}_linux_amd64.tar.gz" && \
tar -xzf "otelcol-contrib_${OTEL_COL_VERSION}_linux_amd64.tar.gz"
COPY otelcol-config.yml /opt/otelcol-config.yml

ENTRYPOINT ["/opt/otelcol-contrib"]
CMD ["--config", "/opt/otelcol-config.yml"]
89 changes: 89 additions & 0 deletions receiver/journaldreceiver/examples/container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Running journaldreceiver in Docker and Kubernetes
The first step to run the journaldreceiver in Docker or Kubernetes is
to build a Docker image containing the Opentelemetry Collector and the
`journalctl` binary. The following `Dockerfile` can be used as a
starting point.

```dockerfile
FROM debian:13-slim

ARG OTEL_COL_VERSION=0.136.0

WORKDIR /opt

RUN apt update && \
apt install -y systemd wget && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN wget "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_COL_VERSION}/otelcol-contrib_${OTEL_COL_VERSION}_linux_amd64.tar.gz" && \
tar -xzf "otelcol-contrib_${OTEL_COL_VERSION}_linux_amd64.tar.gz"
COPY otelcol-config.yml /opt/otelcol-config.yml

ENTRYPOINT ["/opt/otelcol-contrib"]
CMD ["--config", "/opt/otelcol-config.yml"]
```

To build the image setting the Collector version at build time you can
use:
```sh
docker build --build-arg OTEL_COL_VERSION=0.136.0 -t otel-col-journald .
```

You can check the version of the Collector by running:
```sh
docker run --rm -it otel-col-journald:latest --version
```

To check the version of `journalctl` installed, run:
```
docker run --rm -it --entrypoint journalctl otel-col-journald:latest --version
```

## Docker
You can use the provided `otelcol-config.yml` to test the
journaldreceiver. If your journal logs are on `/var/log/journal`, run:

```sh
docker run --rm --mount type=bind,source=/var/log/journal,target=/opt/journal,ro otel-col-journald
```

You will see the journal logs from your machine being displayed by the
debug exporter.

## Kubernetes
The journaldreceiver can be used to ingest the node logs from a
Kubernets cluster, it is a very similar process as running it in
Docker: build the image, deploy a daemonset giving it access to the
journal folder on the nodes.

For this example we will use [Kind](https://kind.sigs.k8s.io/) to spin
up a Kubernetes cluster using Docker container nodes.

First build the docker image as shown above, then start the kind cluster:
```sh
kind create cluster
```

Load the image into the cluster:
```
kind load docker-image otel-col-journald:latest
```

Then deploy the Collector:
```
% kubectl apply -f manifest.yml
configmap/otel-config created
daemonset.apps/otel-collector created
```

Wait for the pod to be ready:
```
% kubectl get pods
NAME READY STATUS RESTARTS AGE
otel-collector-k4fhv 1/1 Running 0 29s
```
Follow the pod logs to see the journaldreceiver working:
```
kubectl logs -f otel-collector-k4fhv # adjust the pod name
```
56 changes: 56 additions & 0 deletions receiver/journaldreceiver/examples/container/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: otel-config
data:
otel-config.yml: |
receivers:
journald:
directory: /opt/journal

exporters:
debug:
verbosity: normal

service:
pipelines:
logs:
receivers: [journald]
exporters: [debug]
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: otel-collector
labels:
app: otel-collector
spec:
selector:
matchLabels:
app: otel-collector
template:
metadata:
labels:
app: otel-collector
spec:
containers:
- name: otel-collector
image: otel-col-journald:latest
# Image is already loaded in the cluster, no need to pull it
# because pulling will fail because it has not been published.
imagePullPolicy: Never
volumeMounts:
- name: otel-config-volume
mountPath: /opt/otelcol-config.yaml
subPath: otel-config.yml
- name: journal-volume
mountPath: /opt/journal
readOnly: true
volumes:
- name: otel-config-volume
configMap:
name: otel-config
- name: journal-volume
hostPath:
path: /run/log/journal/
type: Directory
13 changes: 13 additions & 0 deletions receiver/journaldreceiver/examples/container/otelcol-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
receivers:
journald:
directory: /opt/journal

exporters:
debug:
verbosity: normal

service:
pipelines:
logs:
receivers: [journald]
exporters: [debug]