0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenShiftのテレメトリーデータを転送してみた (Red Hat build of OpenTelemetry)

0
Last updated at Posted at 2025-12-12

これはOpenShift Advent Calendar 2025の12/8の記事です

なぜ我々はプラットフォームのデータを集約するのか

我々が運用するプラットフォームは、Kubernetesやマイクロサービスなどの普及でプラットフォームの内部がかなり複雑化していると思います。それにより問題が起きた場合に、迅速な原因の特定が難しくなっているのでないでしょうか。

Gemini_Generated_Image_i33slti33slti33s.png

では、どうするのかと言うと、内部状態をよく理解し、原因分析できるようにObservabilityが求められます。なので、今回はOpenShiftのRed Hat build of OpenTelemetry(OTEL)を使って、テレメトリーデータを外部へ転送する方法をご紹介しようかと思います。

Red Hat build of OpenTelemetryとは

Red HatがOpeartorとして提供しているOTELになります。デプロイすることで、OpenShiftのテレメトリーデータを集取、加工、転送することができます。テレメトリデータには、ログ/メトリクス/トレースがあります。

執筆時点(2025/12/08)において、Red Hat build of OpenTelemetryはレシーバやプロセッサーなど使える機能にTechnology Previewが多くあります。利用される際は、以下の参考情報から確認してください。

参考情報

今回は、これらを利用して、メトリクスとログを外部へ転送します。

実際に転送してみよう

本記事において、以下を実機で確認します。

  • 外部へOpenShift上のPrometheusからメトリクスを転送する
  • 外部へOpenShift上のPodのログを転送する

検証環境

  • OpenShift 4.18
    • Red Hat build of OpenTelemetry Operator 0.140
  • OpenObserve 0.20.2

OpenObserveはOpenObserve社が開発しているOSSのObservabilityプラットフォームになります。OpenShiftからメトリクスデータを転送するための外部宛先として、このソフトウェアを使用します。

image.png

手順

Red Hat build of OpenTelemetry Operatorのインストール

OpenShiftのコンソールからOperatorをインストールしていきます。
image.png

デフォルトの値のまま、Installをクリックしていきます。
image.png

Operatorのインストールが完了しました。
image.png

メトリクス用のOTELのデプロイ

observabilityのnamespaceを作成します。

oc create ns observability

OpenTelemetryCollectorForMetrics.yamlを作成します。

OpenTelemetryCollectorForMetrics.yaml
piVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-collector
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-monitoring-view
subjects:
  - kind: ServiceAccount
    name: otel-collector
    namespace: observability
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: cabundle
  namespace: observability
  annotations:
    service.beta.openshift.io/inject-cabundle: "true"
--- 
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: observability
spec:
  volumeMounts:
    - name: cabundle-volume
      mountPath: /etc/pki/ca-trust/source/service-ca
      readOnly: true
  volumes:
    - name: cabundle-volume
      configMap:
        name: cabundle
  mode: deployment
  config:
    receivers:
      prometheus:
        config:
          scrape_configs:
            - job_name: 'federate'
              scrape_interval: 15s
              scheme: https
              tls_config:
                ca_file: /etc/pki/ca-trust/source/service-ca/service-ca.crt
              bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
              honor_labels: false
              params:
                'match[]':
                  - '{job="kubelet"}'
              metrics_path: '/federate'
              static_configs:
                - targets:
                  - "prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
    exporters:
      otlphttp:
        endpoint: http://192.168.100.201:5080/api/default
        headers:
          Authorization: "<YOUR TOKEN>"
          organization: default
          stream-name: default
        tls:
          insecure: true
    service:
      pipelines:
        metrics:
          receivers: [prometheus]
          processors: []
          exporters: [otlphttp]

上記をデプロイします。

oc apply -f OpenTelemetryCollectorForMetrics.yaml

OpenObserveからOpenShiftへ転送されたメトリクスを確認します。
image.png

ログ用のOTELのデプロイ

次にログ用のOTELをデプロイします。別のnamespaceを作成します。

oc create ns openshift-logging

OpenTelemetryCollectorForLogs.yamlを作成します。

OpenTelemetryCollectorForLogs.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: otel-collector-deployment
  namespace: openshift-logging
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otel-collector-logs-writer
rules:
 - apiGroups: ["loki.grafana.com"]
   resourceNames: ["logs"]
   resources: ["application"]
   verbs: ["create"]
 - apiGroups: [""]
   resources: ["pods", "namespaces", "nodes"]
   verbs: ["get", "watch", "list"]
 - apiGroups: ["apps"]
   resources: ["replicasets"]
   verbs: ["get", "list", "watch"]
 - apiGroups: ["extensions"]
   resources: ["replicasets"]
   verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-collector-logs-writer
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: otel-collector-logs-writer
subjects:
  - kind: ServiceAccount
    name: otel-collector-deployment
    namespace: openshift-logging
---
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: openshift-logging
spec:
  serviceAccount: otel-collector-deployment
  config:
    extensions:
      bearertokenauth:
        filename: "/var/run/secrets/kubernetes.io/serviceaccount/token"
    receivers:
      otlp:
        protocols:
          grpc: {}
          http: {}
    processors:
      k8sattributes: {}
      resource:
        attributes:
          - key:  kubernetes.namespace_name
            from_attribute: k8s.namespace.name
            action: upsert
          - key:  kubernetes.pod_name
            from_attribute: k8s.pod.name
            action: upsert
          - key: kubernetes.container_name
            from_attribute: k8s.container.name
            action: upsert
          - key: log_type
            value: application
            action: upsert
      transform:
        log_statements:
          - context: log
            statements:
              - set(attributes["level"], ConvertCase(severity_text, "lower"))
    exporters:
      otlphttp:
        endpoint: http://192.168.100.201:5080/api/default
        headers:
          Authorization: "<YOUR TOKEN>"
          organization: default
          stream-name: default
        tls:
          insecure: true
    service:
      extensions: [bearertokenauth]
      pipelines:
        logs:
          receivers: [otlp]
          processors: [k8sattributes, transform, resource]
          exporters: [otlphttp]

上記をデプロイします。

oc apply -f OpenTelemetryCollectorForLogs.yaml

ログを出力するテスト用のJobを作成します。

test.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: telemetrygen
spec:
  template:
    spec:
      containers:
        - name: telemetrygen
          image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:v0.106.1
          args:
            - logs
            - --otlp-endpoint=otel-collector.openshift-logging.svc.cluster.local:4317
            - --otlp-insecure
            - --duration=180s
            - --workers=1
            - --logs=10
            - --otlp-attributes=k8s.container.name="telemetrygen"
      restartPolicy: Never
  backoffLimit: 4

テスト用のJobをデプロイします。

oc apply -f test.yaml

再度ログが転送されているかOpenObserveを確認します。

image.png

まとめ

Red Hat build of OpenTelemetryを使って、OpenShiftのメトリクスやログを転送してみました。今回はOSSのOpenObserveを使いましたが、SaaSがOTLP/gRPCやOTLP/HTTPに対応していれば、簡単にOpenShiftのテレメトリデータが転送できるかもしれないです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?