[Live Webinar] Next-Level O11y: Why Every DevOps Team Needs a RUM Strategy Register today!

Deploy Open Telemetry to Kubernetes in 5 minutes

  • Coralogix
  • March 15, 2023
Share article

OpenTelemetry is an open-source observability framework that provides a vendor-neutral and language-agnostic way to collect and analyze telemetry data. This tutorial will show you how to integrate OpenTelemetry on Kubernetes, a popular container orchestration platform.

Prerequisites:

  • You should have a basic understanding of OpenTelemetry and Kubernetes.
  • You should have a Kubernetes cluster set up and running.
  • You should have a containerized application you want to use with OpenTelemetry and deploy on Kubernetes.

Step 1: Install the OpenTelemetry Collector

The first step is to install the OpenTelemetry Collector on your Kubernetes cluster. You can do this by creating a Kubernetes Deployment and Service for the collector, using the following YAML file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: otel-collector
spec:
  replicas: 1
  selector:
    matchLabels:
      app: otel-collector
  template:
    metadata:
      labels:
        app: otel-collector
    spec:
      containers:
      - name: otel-collector
        image: open-telemetry/opentelemetry-collector
        ports:
        - containerPort: 55678
        env:
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: <your_otel_exporter_endpoint>
---
apiVersion: v1
kind: Service
metadata:
  name: otel-collector
spec:
  selector:
    app: otel-collector
  ports:
  - name: otel-collector-port
    port: 55678
    targetPort: 55678

Step 2: Install the OpenTelemetry Agent

The next step is to install the OpenTelemetry Agent on your Kubernetes cluster. You can do this by creating a Kubernetes DaemonSet for the agent, using the following YAML file:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: otel-agent
spec:
  selector:
    matchLabels:
      app: otel-agent
  template:
    metadata:
      labels:
        app: otel-agent
    spec:
      containers:
      - name: otel-agent
        image: open-telemetry/opentelemetry-agent
        ports:
        - containerPort: 55678
        env:
        - name: OTEL_EXPORTER_OTLP_ENDPOINT
          value: <your_otel_exporter_endpoint>

Step 3: Instrument Your Application

The final step is to instrument your application with OpenTelemetry. You can do this by adding the OpenTelemetry SDK for your programming language to your application. This will depend on the framework and programming language you are using.

Do you always need instrumentation?

When configuring the OpenTelemetry Collector to collect logs on a Kubernetes cluster, you will need to specify the appropriate settings for the log exporter and the log processor.

Here is an example configuration for a Collector that is set up to collect logs from Kubernetes pods and send them to a log sink like Elasticsearch or Logstash.

Begin by configuring the log exporter:

exporters:
  logs:
    type: logstash
    config:
      endpoint: <logstash_endpoint>
      port: <logstash_port>
      protocol: <logstash_protocol>

After your exporter is in place, configure the processor to enable Kubernetes log processing. This will include metadata as part of your Kubernetes logs.

processors:
  logs:
    config:
      k8s:
        enabled: true
        namespace: <your_k8s_namespace>

Finally, configure your Open Telemetry collector to scrape the data that it needs from the appropriate configuration.

scrapers:
  k8s:
    config:
      k8s_sd_configs:
      - role: pod

And that’s it! 

Kubernetes and OpenTelemetry fit perfectly together, and form a platform that is not only observed, but acts as a ready made observability toolkit for all of the applications that run within the cluster. 

Where Modern Observability
and Financial Savvy Meet.

Live Webinar
Next-Level O11y: Why Every DevOps Team Needs a RUM Strategy
April 30th at 12pm ET | 6pm CET
Save my Seat