---
title: Install and configure OTel Collector Contrib on Kubernetes to monitor Elasticsearch
source: https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/install-configure/kubernetes/otel-collector-contrib
---

This guide shows how to deploy the OpenTelemetry Collector Contrib on Kubernetes to automatically discover your Elasticsearch pods, collect cluster, node, and JVM metrics, and stream them to New Relic to monitor your cluster's health and performance.

## Compatibility and requirements [#requirements]

### Supported

-   Elasticsearch 7.16 or later, running as pods in a Kubernetes cluster
-   Helm 3.x install method

### Not supported

-   Kubernetes manifest-based install

### You need

-   A New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key)
-   `kubectl` access to your Kubernetes cluster
-   Helm 3.x installed
-   An Elasticsearch user with the `monitor` or `manage` cluster privilege (see [Elasticsearch security privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html))
-   Outbound HTTPS (port 443) connectivity to New Relic's [OTLP endpoint](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp)
-   An Elasticsearch username and password (if your cluster requires authentication)

## Set up pod labels [#pod-labels]

Each Elasticsearch pod must have the label `app: elasticsearch` for automatic discovery to work. Without this label, the collector won't detect or monitor your pods.

If you're using a StatefulSet or Deployment for Elasticsearch, add the label in the pod template:

```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch
spec:
  template:
    metadata:
      labels:
        app: elasticsearch  # Required for auto-discovery
    spec:
      containers:
      - name: elasticsearch
        image: docker.elastic.co/elasticsearch/elasticsearch:8.x.x
```

For existing pods without the label, update your StatefulSet/Deployment and restart the pods:

```bash
kubectl label pods -l <your-existing-selector> app=elasticsearch -n <namespace>
```

## Prepare credentials and collector settings [#prepare]

Create the credentials the collector needs, then define its Elasticsearch monitoring configuration in a `values.yaml` file. You install the collector with this configuration in the next step.

1.  Create the namespace and a secret for your New Relic credentials:

    ```bash
    kubectl create namespace newrelic
    kubectl create secret generic newrelic-licenses \
      --from-literal=NEWRELIC_LICENSE_KEY=YOUR_LICENSE_KEY_HERE \
      --from-literal=NEWRELIC_OTLP_ENDPOINT=https://otlp.nr-data.net:4318 \
      --from-literal=NEW_RELIC_MEMORY_LIMIT_MIB=100 \
      -n newrelic
    ```

    Replace the license key placeholder, the endpoint with your account's region if you're not on the US datacenter, and the memory limit with what fits your environment.

2.  Create a `values.yaml` file to configure the OpenTelemetry Collector for Elasticsearch monitoring.

    > #### 💡 TIP
    >
    > **Customize for your environment:**
    >
    > **Required changes:**
    >
    > -   **Pod label rule** - The rule `labels["app"] == "elasticsearch"` must match your pod labels. If your Elasticsearch pods use different labels (e.g., `app: es-cluster`), update the rule accordingly: `rule: type == "pod" && labels["app"] == "es-cluster"`
    > -   **Cluster name** - Replace `elasticsearch-cluster` with a unique name to identify your cluster in New Relic. Choose a name that's unique across your New Relic account (e.g., `prod-es-k8s`, `staging-elasticsearch`)
    >
    > **Optional changes:**
    >
    > -   **Port** - Update `9200` if Elasticsearch runs on a different port
    > -   **Authentication** - Add credentials if your Elasticsearch cluster is secured

    ```yaml
    mode: deployment

    image:
      repository: otel/opentelemetry-collector-contrib
      pullPolicy: IfNotPresent

    command:
      name: otelcol-contrib

    resources:
      limits:
        cpu: 500m
        memory: 512Mi
      requests:
        cpu: 200m
        memory: 256Mi

    extraEnvs:
      - name: NEWRELIC_LICENSE_KEY
        valueFrom:
          secretKeyRef:
            name: newrelic-licenses
            key: NEWRELIC_LICENSE_KEY
      - name: NEWRELIC_OTLP_ENDPOINT
        valueFrom:
          secretKeyRef:
            name: newrelic-licenses
            key: NEWRELIC_OTLP_ENDPOINT
      - name: NEW_RELIC_MEMORY_LIMIT_MIB
        valueFrom:
          secretKeyRef:
            name: newrelic-licenses
            key: NEW_RELIC_MEMORY_LIMIT_MIB
      - name: K8S_CLUSTER_NAME
        value: "elasticsearch-cluster"

    clusterRole:
      create: true
      rules:
        - apiGroups: [""]
          resources: ["pods", "nodes", "nodes/stats", "nodes/proxy"]
          verbs: ["get", "list", "watch"]
        - apiGroups: ["apps"]
          resources: ["replicasets"]
          verbs: ["get", "list", "watch"]

    config:
      extensions:
        health_check:
          endpoint: 0.0.0.0:13133
        k8s_observer:
          auth_type: serviceAccount
          observe_pods: true
          observe_nodes: true
      receivers:
        receiver_creator/elasticsearch:
          watch_observers: [k8s_observer]
          receivers:
            elasticsearch:
              rule: type == "pod" && labels["app"] == "elasticsearch"
              config:
                endpoint: 'http://`endpoint`:9200'
                collection_interval: 30s
                metrics:
                  elasticsearch.os.cpu.usage:
                    enabled: true
                  elasticsearch.cluster.data_nodes:
                    enabled: true
                  elasticsearch.cluster.health:
                    enabled: true
                  elasticsearch.cluster.in_flight_fetch:
                    enabled: true
                  elasticsearch.cluster.nodes:
                    enabled: true
                  elasticsearch.cluster.pending_tasks:
                    enabled: true
                  elasticsearch.cluster.shards:
                    enabled: true
                  elasticsearch.cluster.state_update.time:
                    enabled: true
                  elasticsearch.index.documents:
                    enabled: true
                  elasticsearch.index.operations.merge.current:
                    enabled: true
                  elasticsearch.index.operations.time:
                    enabled: true
                  elasticsearch.node.cache.count:
                    enabled: true
                  elasticsearch.node.cache.evictions:
                    enabled: true
                  elasticsearch.node.cache.memory.usage:
                    enabled: true
                  elasticsearch.node.shards.size:
                    enabled: true
                  elasticsearch.node.cluster.io:
                    enabled: true
                  elasticsearch.node.documents:
                    enabled: true
                  elasticsearch.node.disk.io.read:
                    enabled: true
                  elasticsearch.node.disk.io.write:
                    enabled: true
                  elasticsearch.node.fs.disk.available:
                    enabled: true
                  elasticsearch.node.fs.disk.total:
                    enabled: true
                  elasticsearch.node.http.connections:
                    enabled: true
                  elasticsearch.node.ingest.documents.current:
                    enabled: true
                  elasticsearch.node.ingest.operations.failed:
                    enabled: true
                  elasticsearch.node.open_files:
                    enabled: true
                  elasticsearch.node.operations.completed:
                    enabled: true
                  elasticsearch.node.operations.current:
                    enabled: true
                  elasticsearch.node.operations.get.completed:
                    enabled: true
                  elasticsearch.node.operations.time:
                    enabled: true
                  elasticsearch.node.shards.reserved.size:
                    enabled: true
                  elasticsearch.index.shards.size:
                    enabled: true
                  elasticsearch.os.cpu.load_avg.1m:
                    enabled: true
                  elasticsearch.os.cpu.load_avg.5m:
                    enabled: true
                  elasticsearch.os.cpu.load_avg.15m:
                    enabled: true
                  elasticsearch.os.memory:
                    enabled: true
                  jvm.gc.collections.count:
                    enabled: true
                  jvm.gc.collections.elapsed:
                    enabled: true
                  jvm.memory.heap.max:
                    enabled: true
                  jvm.memory.heap.used:
                    enabled: true
                  jvm.memory.heap.utilization:
                    enabled: true
                  jvm.threads.count:
                    enabled: true
                  elasticsearch.index.segments.count:
                    enabled: true
                  elasticsearch.index.operations.completed:
                    enabled: true
                  elasticsearch.node.script.cache_evictions:
                    enabled: false
                  elasticsearch.node.cluster.connections:
                    enabled: false
                  elasticsearch.node.pipeline.ingest.documents.preprocessed:
                    enabled: false
                  elasticsearch.node.thread_pool.tasks.queued:
                    enabled: false
                  elasticsearch.cluster.published_states.full:
                    enabled: false
                  jvm.memory.pool.max:
                    enabled: false
                  elasticsearch.node.script.compilation_limit_triggered:
                    enabled: false
                  elasticsearch.node.shards.data_set.size:
                    enabled: false
                  elasticsearch.node.pipeline.ingest.documents.current:
                    enabled: false
                  elasticsearch.cluster.state_update.count:
                    enabled: false
                  elasticsearch.node.fs.disk.free:
                    enabled: false
                  jvm.memory.nonheap.used:
                    enabled: false
                  jvm.memory.pool.used:
                    enabled: false
                  elasticsearch.node.translog.size:
                    enabled: false
                  elasticsearch.node.thread_pool.threads:
                    enabled: false
                  elasticsearch.cluster.state_queue:
                    enabled: false
                  elasticsearch.node.translog.operations:
                    enabled: false
                  elasticsearch.memory.indexing_pressure:
                    enabled: false
                  elasticsearch.node.ingest.documents:
                    enabled: false
                  jvm.classes.loaded:
                    enabled: false
                  jvm.memory.heap.committed:
                    enabled: false
                  elasticsearch.breaker.memory.limit:
                    enabled: false
                  elasticsearch.indexing_pressure.memory.total.replica_rejections:
                    enabled: false
                  elasticsearch.breaker.memory.estimated:
                    enabled: false
                  elasticsearch.cluster.published_states.differences:
                    enabled: false
                  jvm.memory.nonheap.committed:
                    enabled: false
                  elasticsearch.node.translog.uncommitted.size:
                    enabled: false
                  elasticsearch.node.script.compilations:
                    enabled: false
                  elasticsearch.node.pipeline.ingest.operations.failed:
                    enabled: false
                  elasticsearch.indexing_pressure.memory.limit:
                    enabled: false
                  elasticsearch.breaker.tripped:
                    enabled: false
                  elasticsearch.indexing_pressure.memory.total.primary_rejections:
                    enabled: false
                  elasticsearch.node.thread_pool.tasks.finished:
                    enabled: false
      processors:
        memory_limiter:
          check_interval: 60s
          limit_mib: ${env:NEW_RELIC_MEMORY_LIMIT_MIB}
        cumulativetodelta: {}
        resource/cluster:
          attributes:
            - key: k8s.cluster.name
              value: "${env:K8S_CLUSTER_NAME}"
              action: insert
        resource/cluster_name_override:
          attributes:
            - key: elasticsearch.cluster.name
              value: "${env:K8S_CLUSTER_NAME}"
              action: upsert
        resourcedetection:
          detectors: [env, system]
          system:
            resource_attributes:
              host.name:
                enabled: true
              host.id:
                enabled: true
              os.type:
                enabled: true
        batch:
          timeout: 10s
          send_batch_size: 1024
        attributes/cardinality_reduction:
          actions:
            - key: process.pid
              action: delete
            - key: process.parent_pid
              action: delete
            - key: k8s.pod.uid
              action: delete
        transform/metadata_nullify:
          metric_statements:
            - context: metric
              statements:
                - set(description, "")
                - set(unit, "")
      exporters:
        otlphttp:
          endpoint: "${env:NEWRELIC_OTLP_ENDPOINT}"
          headers:
            api-key: "${env:NEWRELIC_LICENSE_KEY}"
      service:
        extensions: [health_check, k8s_observer]
        pipelines:
          metrics/elasticsearch:
            receivers: [receiver_creator/elasticsearch]
            processors: [memory_limiter, resourcedetection, resource/cluster, resource/cluster_name_override, attributes/cardinality_reduction, cumulativetodelta, transform/metadata_nullify, batch]
            exporters: [otlphttp]
    ```

    You can optionally secure this cluster with authentication and SSL. See [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration#secured).

### Configuration parameters [#configuration-parameters]

The following table describes the key configuration parameters used in the `values.yaml` above:

| Parameter                                       | Description                                                                                                                                                            |
| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rule`                                          | The pod-matching rule used for auto-discovery. Update `labels["app"] == "elasticsearch"` to match your pod labels.                                                     |
| `endpoint`                                      | The Elasticsearch endpoint scraped on each discovered pod. Update port `9200` if Elasticsearch runs on a different port, and use `https` for a secured cluster.        |
| `collection_interval`                           | The interval between metric scrapes. The default is 30s.                                                                                                               |
| `elasticsearch-cluster` (in `K8S_CLUSTER_NAME`) | A unique name identifying this cluster in New Relic. Replace with a name that's unique across your account.                                                            |
| `NEW_RELIC_MEMORY_LIMIT_MIB`                    | The memory limit, in MiB, for the collector's `memory_limiter` processor. Set to fit your environment.                                                                 |
| `NEWRELIC_LICENSE_KEY`                          | Your New Relic [license key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#ingest-license-key).                                                   |
| `NEWRELIC_OTLP_ENDPOINT`                        | The New Relic OTLP endpoint for your account's region. See [New Relic OTLP endpoints](https://docs.newrelic.com/docs/opentelemetry/best-practices/opentelemetry-otlp). |

## Install and configure the OpenTelemetry Collector Contrib via Helm [#install-helm]

Deploy the OpenTelemetry Collector Contrib to your cluster. Helm applies the configuration from the `values.yaml` file you just created.

1.  Add and update the OpenTelemetry Helm chart repository:

    ```bash
    helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
    helm repo update
    ```

2.  Deploy the OpenTelemetry Collector Contrib:

    ```bash
    helm upgrade --install elasticsearch-otel-collector open-telemetry/opentelemetry-collector \
      --namespace newrelic \
      --create-namespace \
      -f values.yaml
    ```

## Verify your install [#verify]

Within ~5 minutes of installing, run this query in New Relic to confirm data is flowing (replace `elasticsearch-cluster` with your cluster's name):

```sql
FROM Metric
SELECT *
WHERE metricName LIKE 'elasticsearch.%'
  AND instrumentation.provider = 'opentelemetry'
  AND k8s.cluster.name = 'elasticsearch-cluster'
SINCE 10 minutes ago
```

> #### 💡 TIP
>
> You can also check the collector itself: the pod should be in a `Running` state (`kubectl get pods -n newrelic`, name like `elasticsearch-otel-collector-<hash>`), with no connection errors in the pod logs (`kubectl logs -n newrelic -l app.kubernetes.io/name=opentelemetry-collector -f`).

If you don't see data within ~5 minutes, see [Kubernetes troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/troubleshooting#kubernetes-troubleshooting).

## Find and use your data [#find-and-use]

Once New Relic collects your data, you can access Elasticsearch monitoring through the New Relic UI.

To find your Elasticsearch dashboard in New Relic:

1.  Go to **one.newrelic.com > Integrations & Agents**.
2.  Under the **All** tab, click **Dashboards**, then search for **Elasticsearch (OpenTelemetry Collector)** to view the dashboard.

Or, from the left navigation:

1.  Click **Dashboards**.
2.  Search for the **Elasticsearch (OpenTelemetry Collector)** dashboard to view it.

After setting up Elasticsearch monitoring with OTel Collector Contrib, you can:

-   [Create custom dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/) to visualize your Elasticsearch metrics
-   [Set up alerts](https://docs.newrelic.com/docs/alerts/create-alert/create-alert-condition/alert-conditions/) for critical cluster health and performance thresholds
-   [Explore your data](https://docs.newrelic.com/docs/query-your-data/explore-query-data/browse-data/introduction-data-explorer/) using New Relic query capabilities

> #### 💡 TIP
>
> **Correlate APM with Elasticsearch**: To connect your APM application and Elasticsearch cluster, include the resource attribute `es.cluster.name="your-cluster-name"` in your APM metrics. This lets you view APM and Elasticsearch data together in New Relic.

## Related articles [#related-articles]

-   [Advanced configuration](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/advanced-configuration)
-   [Correlate APM with Elasticsearch using distributed tracing](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/distributed-tracing)
-   [Elasticsearch metrics reference](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/metrics-reference)
-   [Elasticsearch troubleshooting](https://docs.newrelic.com/docs/opentelemetry/integrations/elasticsearch/troubleshooting)
