# Configure the collector Helm chart

Configure the [Better Stack collector](https://betterstack.com/docs/logs/collector/) Helm chart with your `values.yaml` and Kubernetes annotations. For every chart option, see the [values.yaml](https://github.com/BetterStackHQ/collector-helm-chart/blob/main/values.yaml) file.

## Using Secrets and Config Maps in Kubernetes

Keep `COLLECTOR_SECRET` out of your `values.yaml` and version control. Store it in a Kubernetes [Secret](https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/):

```bash
[label Create Kubernetes secret]
kubectl create secret generic better-stack-collector-secret \
  --from-literal=COLLECTOR_SECRET='$COLLECTOR_SECRET'
```

Reference the Secret in your `values.yaml`. Set other environment variables from a [ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) the same way:

```yaml
[label values.yaml]
collector:
  env:
    # Leave this empty when using a secret
    COLLECTOR_SECRET: ""
  envFrom:
    - secretRef:
        name: better-stack-collector-secret
    - configMapRef:
        name: my-collector-config
ebpf:
  envFrom:
    - configMapRef:
        name: my-ebpf-config
```

[warning]
#### Environment variables have precedence over Secrets and Config Maps

Environment variables set explicitly in `collector.env` or `ebpf.env` will take precedence over variables sourced from `envFrom`.
[/warning]

## Setting Pod Priority

Give the collector pods a `PriorityClass` so they are scheduled first and less likely to be evicted during resource shortages. Set `priorityClassName` in your `values.yaml` to a `PriorityClass` already defined in your cluster:

```yaml
[label values.yaml]
priorityClassName: "high-priority-nonpreempting"
```

Learn more about Pod Priority and Preemption in [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/).

## Sampling logs and disabling tracing with Kubernetes annotations

You can use Kubernetes pod and namespace annotations to control the sampling of logs and collection of traces. The annotations take precedence over the UI for annotated resources.

Services and namespaces annotated with `exclude-from-services` are not added to the [Services](https://telemetry.betterstack.com/team/0/services) list in Better Stack. Use this annotation for ephemeral pods to reduce noise.

[code-tabs]
```yaml
[label namespace.yaml]
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    betterstack.com/collect-traces: "true"
    betterstack.com/log-sampling: "0.5" # [0-1], 0 = logging disabled, 1 = 100%
    betterstack.com/exclude-from-services: "true"
```
```yaml
[label deployment.yaml]
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    betterstack.com/collect-traces: "true"
    betterstack.com/log-sampling: "0.5" # [0-1], 0 = logging disabled, 1 = 100%
    betterstack.com/exclude-from-services: "true"
```
[/code-tabs]

## Collect additional logs

Send any log files from the node's filesystem to Better Stack. For example, add the following configuration to your `manual.vector.yaml` file to send the logs from `/var/www/custom.log` and any file matching `/var/www/**/service.*.log`:

```yaml
[label Sending custom logs]
sources:
  better_stack_logs_custom_file:
    type: file
    read_from: beginning
    ignore_older_secs: 259200 # send only log lines newer than 3 days
    include:
      - "/host/var/www/custom.log"
      - "/host/var/www/**/service.*.log"
```

Any source with a name starting with `better_stack_logs_` is forwarded to the logs sink.

## Mount fewer paths into the collector container

Collector mounts the root filesystem **read-only** into the collector container by default. You can mount only select paths into the container:

```bash
[label Mount select paths]
helm repo add better-stack https://betterstackhq.github.io/collector-helm-chart
helm repo update
helm install better-stack-collector better-stack/collector \
  --set collector.env.COLLECTOR_SECRET="$COLLECTOR_SECRET" \
  --set collector.hostMounts.paths[0]=/var/www/custom \
  --set collector.hostMounts.paths[1]=/var/lib/something
```

Selected paths will be mounted read-only under the `/host` prefix, e.g. `/host/var/www/custom`.

## Required permissions

The `ebpf` container requires privileged access as it runs the eBPF code responsible for generating traces. The collector container doesn't request privileged access.

## Need help?

Please let us know at hello@betterstack.com.  
We're happy to help! 🙏
