Skip to main content
This page installs two OpenTelemetry Collectors in your Kubernetes cluster with the upstream Helm chart. The node collector runs on every node. It sends container logs and the CPU and memory use of nodes, pods, and containers. The cluster collector runs as one replica. It sends requests, limits, node capacity, pod phase, and workload status from the Kubernetes API.

What you’ll learn

  • How to give both collectors the Sherlock endpoint and token
  • How to select the containers whose logs you send
  • How JSON log lines become a message, a severity, and a trace link
  • Where the data appears in Sherlock, and how to change the configuration later

Prerequisites

  • A Kubernetes cluster whose container runtime writes logs under /var/log/pods, as containerd and CRI-O do.
  • kubectl with access to the cluster, and Helm 3.
  • The Endpoint and the Bearer Token from Settings → Collector. Click Reveal to see the token.
  • The env value for this cluster, prod or dev. See Environments.
This page uses the Helm chart open-telemetry/opentelemetry-collector 0.176.1. The chart installs the image otel/opentelemetry-collector-contrib 0.162.0.

How it works

The cluster collector runs as exactly one replica, because every replica reports the same objects. Nothing sends data to the collectors, so they open no ports.

Steps

1

Store the token in a Secret

Create a namespace for the collectors and a Secret with your token. Both collectors read the token from this Secret.
The collectors read the token into the environment variable SHERLOCK_TOKEN. The token does not appear in the values files.
2

Write the node collector values file

Save this file as sherlock-collector-values.yaml. Then change three values:
  1. Replace CHANGE_ME_ENDPOINT with the Endpoint from Settings → Collector.
  2. Replace CHANGE_ME_NAMESPACE with the namespace of your application. Add one include line for each namespace.
  3. If the cluster is not production, change prod to dev.
sherlock-collector-values.yaml
Each include entry is a glob:The exclude entry stops the collector from reading its own logs. Keep it.
3

Write the cluster collector values file

Save this file as sherlock-cluster-collector-values.yaml. Make the same changes to CHANGE_ME_ENDPOINT and prod as in the previous step.
sherlock-cluster-collector-values.yaml
4

Install the charts

The chart creates a ServiceAccount, a ClusterRole with read access, its binding, and a ConfigMap for each collector.

Verify

  1. Check that the collectors run and start without errors:
  2. Open Logs in Sherlock and select the source for your env value. New lines appear within about a minute. The collector sends only lines that your containers write after it starts.
  3. Open Metrics in the same source. Select k8s.pod.memory.working_set for usage, or k8s.pod.phase for cluster state.

What it collects

The transform/json processor changes log lines that start with {: Plain-text lines keep their body and get no severity.

Change the configuration

  1. Edit the values file.
  2. Run the helm upgrade --install command for that collector again.
The collectors keep data in memory. When a collector restarts, it starts again at the end of each log file, so lines that containers write during the restart are lost. If Sherlock is unreachable, the collector retries each batch for up to 5 minutes and then drops it.

Severity for a plain-text log format

To set the severity of plain-text lines from one container, add a statement group to transform/json after the resource group. This example reads the level of PostgreSQL lines from a container named postgres. Change the name to match your container.

Troubleshooting

Compare the endpoint in the values files and the token in the Secret with Settings → Collector. The endpoint is the full URL shown there. After you change the Secret, restart the collectors with kubectl rollout restart.
Check that an include pattern matches. The directory is <namespace>_<pod>_<pod-uid>. The container name is the name in the pod spec, not the image name. To list the container names of a pod, run:
Check the collector log for export errors first. If the log is clean, metrics are not enabled for your organization. Ask us to enable them. No change in the cluster is necessary.
Check the env value in both values files. Matching is exact and case-sensitive. See Environments.

OpenTelemetry SDKs and collectors

Endpoint, header, and the env attribute for any collector.

Environments

How the env value routes the data of the cluster into a source.

Logs

Search syntax, facets, and the trace link.

Metrics

Chart a metric, group by an attribute, and the SQL tab.