OpenTelemetry Operator for Kubernetes

repository·main·Indexed 23 days ago

https://github.com/open-telemetry/opentelemetry-operator

The OpenTelemetry Operator for Kubernetes automates the deployment and management of OpenTelemetry Collectors and provides automatic instrumentation for Kubernetes workloads. It includes components such as the OpAMP Bridge for reporting and managing collector state via the OpAMP protocol, the Target Allocator for managing collector fleets, and a must-gather tool for diagnostics and troubleshooting.

Tokens
205.6K
Snippets
174
Records
1.2K
Agent score
81%

What's inside opentelemetry-operator

  1. Overview of the OpenTelemetryCollector Custom Resource

    main

    The OpenTelemetryCollector is a Custom Resource (CR) used to manage OpenTelemetry Collector instances within a Kubernetes cluster via the OpenTelemetry Operator. It allows you to define how collectors are deployed, how they are injected into workloads, and how they observe the cluster.

    Key management capabilities include:

    • Deployment modes: Choosing how the collector is deployed (e.g., as a sidecar or a standalone deployment).
    • Sidecar injection: Automatically injecting collectors into application pods.
    • Image pull secrets: Configuring credentials for pulling private collector images.
    • Cluster Observability: Using the ClusterObservability controller to manage cluster-wide telemetry collection.
  2. OpenTelemetry Operator Documentation Overview

    main

    The OpenTelemetry Operator documentation provides comprehensive guides for managing OpenTelemetry in Kubernetes. Key areas include:

    • Getting Started: Initial setup and quickstart guides.
    • Core Concepts: Understanding the operator's mental model and abstractions.
    • Component Guides: Detailed documentation for specific components:
      • Collector: Managing OpenTelemetry Collector instances.
      • Auto-instrumentation: Automatically injecting instrumentation into applications.
      • Target Allocator: Managing Prometheus target discovery.
      • OpAMP Bridge: Using the OpenTelemetry Agent Management Protocol.
    • Reference & Troubleshooting: Technical references and guides for resolving common issues.
  3. API reference for OpenTelemetry Operator CRDs

    main

    The OpenTelemetry Operator manages several Custom Resource Definitions (CRDs) to automate observability in Kubernetes. The primary resources you will interact with are:

    • Instrumentation: Used to configure and inject OpenTelemetry instrumentation (like auto-instrumentation) into your applications.
    • OpAMPBridge: Used to manage OpAMP (Open Agent Management Protocol) bridges.
    • OpenTelemetryCollector: Used to manage the lifecycle and configuration of OpenTelemetry Collector instances.
    • TargetAllocator: Used to manage Target Allocator resources, typically for Prometheus-style scraping configurations.
  4. Understand the configuration structure for assembling deployment units

    main

    The config directory uses Kustomize to assemble the OpenTelemetry Operator's deployment units. The directory structure is organized as follows:

    • certmanager: Kustomize options for integration with cert-manager.
    • crd: Kustomize options for Custom Resource Definitions (CRDs), including bases (auto-generated from code annotations via make manifests) and patches.
    • default: The Kustomize entry point used to generate the final distribution YAML file.
    • manager: Defines the operator's Deployment.
    • manifests: Contains the resulting CSV (ClusterServiceVersion) and its bases.
    • prometheus: Contains the ServiceMonitor used to expose operator metrics.
    • rbac: Defines the RBAC rules required for the operator.
    • samples: A set of example resources for specific scenarios, which are bundled into the final CSV.
    • webhook: Contains the Webhook configuration and service definitions.
  5. What is the OpAMP Bridge?

    main

    The OpAMP Bridge is an optional component of the OpenTelemetry Operator that implements the agent-side of the OpAMP protocol. It allows you to report and manage the state of OpenTelemetry Collectors in Kubernetes by communicating with an OpAMP server.

    Key capabilities include:

    • Reporting: Sends the status and effective configuration of OpenTelemetryCollector CRD instances to an OpAMP server.
    • Management: Receives configurations from an OpAMP server and performs CRUD operations on the Kubernetes API server to modify OpenTelemetryCollector resources.
    • Telemetry: Emits its own telemetry to an OTLP/HTTP endpoint.
  6. What is the Target Allocator and how does it work?

    main

    The Target Allocator (TA) is an optional component of the OpenTelemetry Collector Custom Resource (CR) used to decouple service discovery from metric collection. It allows Prometheus metrics to be collected by OTel Collectors without requiring a full Prometheus installation.

    Core Functions:

    1. Even Distribution: It discovers Prometheus targets and distributes them among a pool of OTel Collectors.
    2. CR Discovery: It discovers Prometheus Custom Resources (like ServiceMonitor and PodMonitor) to automatically add new jobs to the scrape configuration.

    Workflow:

    1. The TA discovers metrics targets and available OTel Collectors.
    2. The TA assigns metrics targets to specific Collectors.
    3. OTel Collectors query the TA for the metrics endpoints they are responsible for scraping.
    4. The OTel Collectors' prometheus receiver scrapes the assigned targets.

    Deployment Note: The Target Allocator currently supports statefulset and daemonset deployment modes of the OpenTelemetryCollector CR.

  7. Configure ephemeral volumes with volumeClaimTemplates

    main

    Ephemeral volumes are handled by a cluster storage driver and are tied to the pod's lifecycle (created before the pod starts, deleted when the pod is removed). Use this when you need dynamic volume provisioning via a PersistentVolumeClaim (PVC).

    To use this, you must provide a volumeClaimTemplate. The operator will create a stand-alone PVC that the pod owns. The PVC name will follow the pattern <pod name>-<volume name>.

    Note: If a PVC with that name already exists but is not owned by the pod, the pod will be blocked from starting to prevent accidental volume attachment. You must update the existing PVC with an owner reference to the pod in such cases.

  8. Configure container command and arguments with variable expansion

    main

    When defining command or args for an additional container in a TargetAllocator, you can use variable references in the format $(VAR_NAME). These references are expanded using the container's environment.

    To escape the expansion syntax and use a literal $(VAR_NAME) string, use double dollar signs: $$. For example, "$$(VAR_NAME)" will result in the literal string "$(VAR_NAME)". Note that escaped references are never expanded, even if the variable exists in the environment.

  9. Transition to Instrumentation v1beta1

    main

    The OpenTelemetry Operator is introducing the v1beta1 version of the Instrumentation Custom Resource Definition (CRD). This version is a breaking change from v1alpha1 and is designed to provide API stability and align with OpenTelemetry's declarative configuration initiative.

    Key improvements in v1beta1 include:

    • Support for strongly-typed spec.declarativeConfig alongside spec.envConfig.
    • Explicit OTLP exporter protocol specification to resolve ambiguity between HTTP and gRPC.
    • Normalized per-language resource fields and unified JSON tags.
    • Consolidation of Resource and Defaults into a single top-level spec.resource field.
    • Migration of injection control from annotations to labels to support webhook filtering via objectSelector.
  10. Configure label selectors for Prometheus CR components

    main

    The OpenTelemetryCollector.spec.targetAllocator.prometheusCR configuration uses label selectors to discover various resources. For all selector types (probes, scrape configs, namespaces, and service monitors), you can use two methods that are ANDed together:

    1. matchLabels: A map of {key, value} pairs. This is a shorthand for an expression where the operator is In and the values array contains only that single value.
    2. matchExpressions: A list of complex requirements allowing for more advanced logic.

    Selector Behavior:

    • An empty label selector matches all objects.
    • A null label selector matches no objects.