OpenTelemetry系列 - 第4篇 OpenTelemetry K8S生态

目录

    • 一、【Helm】添加OTel Helm repo
    • 二、【Helm Chart】OTel Collector
      • 2.1 daemonset
      • 2.2 deloyment
    • 三、【K8S Operator】OTel Operator
      • 3.1 安装OTel Operator
      • 3.2 部署OpenTelemetryCollector
        • 3.2.1 Deloyment Mode
        • 3.2.2 DeamonSet Mode
        • 3.2.3 StatefulSetMode
        • 3.2.4 Sidecar Mode
      • 3.3 部署Instrumentation - 配置应用端自动注入OTel Agent
        • 3.3.1 全局配置Instrumentation
        • 3.3.2 工作负载通过annotation启用自动注入
        • 3.3.3 Pod内多个container注入
        • 3.3.4 Java Pod自动注入
        • 3.3.5 剔除/actuator/health

一、【Helm】添加OTel Helm repo

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

二、【Helm Chart】OTel Collector

收集器可以部署为以下四种模式之一:

  • deployment(默认)
  • daemonSet
  • statefulSet

默认模式为deployment。

helm install otel-collector open-telemetry/opentelemetry-collector \
--set mode=<value>
helm install otel-collector open-telemetry/opentelemetry-collector \
--values <path where you saved the chart>

2.1 daemonset

部署OpenTelemetry Collector的daemonset实例,以收集节点(node)和运行在这些节点上的工作负载(workloads)相关的遥测数据(telemetry)。使用daementset来保证在所有节点上都安装了这个收集器实例。daemenset收集器的每个实例将只从其运行的节点收集数据。

收集器的实例将使用以下组件:

  • OTLP Receiver:收集应用程序跟踪、度量和日志。
  • Kubernetes Attributes Processor:将Kubernetes元数据添加到传入的应用遥测中。
  • Kubeletstats Receiver:从kubelet上的API服务器提取节点、pod和容器指标。
  • Filelog Receiver:用于收集写入stdout/stderr的Kubernetes日志和应用程序日志(/var/log/pods/*/*/*.log)。

values-for-daemonset.yaml:

mode: daemonsetpresets:# enables the k8sattributesprocessor and adds it to the traces, metrics, and logs pipelineskubernetesAttributes:enabled: true# enables the kubeletstatsreceiver and adds it to the metrics pipelineskubeletMetrics:enabled: true# Enables the filelogreceiver and adds it to the logs pipelineslogsCollection:enabled: true
## The chart only includes the loggingexporter by default
## If you want to send your data somewhere you need to
## configure an exporter, such as the otlpexporter
# config:
# exporters:
#   otlp:
#     endpoint: "<SOME BACKEND>"
# service:
#   pipelines:
#     traces:
#       exporters: [ otlp ]
#     metrics:
#       exporters: [ otlp ]
#     logs:
#       exporters: [ otlp ]

2.2 deloyment

部署Collector的deloyment实例,以收集与整个集群相关的遥测数据。只有一个副本的部署确保我们不会产生重复的数据。

收集器的实例将使用以下组件:

  • Kubernetes Cluster Receiver:收集集群级指标和实体事件。
  • Kubernetes Objects Receiver:从Kubernetes API服务器收集对象,例如events。

values-for-deloyment

mode: deployment# We only want one of these collectors - any more and we'd produce duplicate data
replicaCount: 1presets:# enables the k8sclusterreceiver and adds it to the metrics pipelinesclusterMetrics:enabled: true# enables the k8sobjectsreceiver to collect events only and adds it to the logs pipelineskubernetesEvents:enabled: true
## The chart only includes the loggingexporter by default
## If you want to send your data somewhere you need to
## configure an exporter, such as the otlpexporter
# config:
# exporters:
#   otlp:
#     endpoint: "<SOME BACKEND>"
# service:
#   pipelines:
#     traces:
#       exporters: [ otlp ]
#     metrics:
#       exporters: [ otlp ]
#     logs:
#       exporters: [ otlp ]

三、【K8S Operator】OTel Operator

OTel K8S整体架构:
在这里插入图片描述

3.1 安装OTel Operator

$ helm install \
--set admissionWebhooks.certManager.enabled=false \
--set admissionWebhooks.certManager.autoGenerateCert=true \
opentelemetry-operator open-telemetry/opentelemetry-operator
helm uninstall opentelemetry-operator

收集器可以部署为以下四种模式之一:

  • deployment(默认)
  • daemonSet
  • statefulSet
  • sidecar

默认模式为deployment。

3.2 部署OpenTelemetryCollector

3.2.1 Deloyment Mode

独立部署、运维Collector,方便scale、回滚版本。

$ kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:name: my-collector
spec:mode: deployment # This configuration is omittable.config: |receivers:jaeger:protocols:grpc:processors:exporters:debug:service:pipelines:traces:receivers: [jaeger]processors: []exporters: [debug]
EOF
3.2.2 DeamonSet Mode

作为DaemonSet运行Collector于每个K8s Node之上,收集Node上pod信息。

$ kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:name: my-collector
spec:mode: daemonsethostNetwork: trueconfig: |receivers:jaeger:protocols:grpc:processors:exporters:debug:verbosity: detailedservice:pipelines:traces:receivers: [jaeger]processors: []exporters: [debug]
EOF
3.2.3 StatefulSetMode

将Collector部署为StatefulSet基本上有三个主要优势:

  • Collector实例的name可预测
    如果使用上述两种方法来部署Collector,则Collector实例的pod名称将是唯一的(它的名称加上随机序列)。但是,statfulset中的每个Pod都从statfulset的名称和Pod的序号(my-col-0、my-col-1、my-col-2等)中派生其主机名。
  • 当Collector副本失败时,将安排重新调度
    如果Collector pod在StatefulSet中失败,Kubernetes将尝试重新调度具有相同名称的新pod到同一节点。Kubernetes也会尝试将相同的粘性身份(例如volumnes)附加到新的pod上。
$ kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:name: my-collector
spec:mode: statefulsetreplicas: 3config: |receivers:jaeger:protocols:grpc:processors:exporters:debug:service:pipelines:traces:receivers: [jaeger]processors: []exporters: [debug]
EOF
3.2.4 Sidecar Mode

将Collector作为sidecar注入Pod中,
sidecar模式的最大优点是,它允许人们尽可能快速、可靠地从应用程序中卸载遥测数据。这个Collector实例将在容器级别上工作,不会创建新的pod,这对于保持Kubernetes集群的整洁和易于管理是完美的。此外,当您希望使用不同的收集/导出策略时,还可以使用sidecar模式,这正好适合此应用程序。
一旦Collector Sidecar实例存在于给定的名称空间中,您就可以从该名称空间为deployment注入sidecar(以下2种方式任选1种即可):

  • 为Deployment添加annontation - sidecar.opentelemetry.io/inject: true
  • 为Namespace添加annontation - sidecar.opentelemetry.io/inject: true
$ kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:name: sidecar-for-my-app
spec:mode: sidecarconfig: |receivers:jaeger:protocols:thrift_compact:processors:exporters:debug:service:pipelines:traces:receivers: [jaeger]processors: []exporters: [debug]
EOF
$ kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: my-applabels:app: my-app
spec:selector:matchLabels:app: my-appreplicas: 1template:metadata:labels:app: my-appannotations:sidecar.opentelemetry.io/inject: "true" # CORRECTspec:containers:- name: myappimage: jaegertracing/vertx-create-span:operator-e2e-testsports:- containerPort: 8080protocol: TCP
EOF

3.3 部署Instrumentation - 配置应用端自动注入OTel Agent

operator可以注入和配置OpenTelemetry自动注入agent。目前支持:

  • Apache HTTPD
  • DotNet
  • Go
  • Java
  • Nginx
  • NodeJS
  • Python
3.3.1 全局配置Instrumentation
kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:name: my-instrumentation
spec:exporter:endpoint: http://otel-collector:4317propagators:- tracecontext- baggage- b3sampler:type: parentbased_traceidratioargument: "0.25"python:env:# Required if endpoint is set to 4317.# Python autoinstrumentation uses http/proto by default# so data must be sent to 4318 instead of 4317.- name: OTEL_EXPORTER_OTLP_ENDPOINTvalue: http://otel-collector:4318dotnet:env:# Required if endpoint is set to 4317.# Dotnet autoinstrumentation uses http/proto by default# See https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/888e2cd216c77d12e56b54ee91dafbc4e7452a52/docs/config.md#otlp- name: OTEL_EXPORTER_OTLP_ENDPOINTvalue: http://otel-collector:4318go:env:# Required if endpoint is set to 4317.# Go autoinstrumentation uses http/proto by default# so data must be sent to 4318 instead of 4317.- name: OTEL_EXPORTER_OTLP_ENDPOINTvalue: http://otel-collector:4318
EOF

以上部署成功的CR Instrumentation可以通过如下命令查询:

kubectl get otelinst.
3.3.2 工作负载通过annotation启用自动注入

通过添加annotation启动自动注入:

  • 向pod添加annotation以启用注入
  • 将annotation添加到namespace中,以便该名称空间中的所有pod都将获得检测
  • 将annotation添加到单独的PodSpec对象中,这些对象可以作为Deployment、Statefulset和其他资源的一部分使用

Java:

instrumentation.opentelemetry.io/inject-java: "true"
# 注入到指定的container中(适用于一个Pod中有多个container)
# 如不指定则默认注入到第一个container中,
# 可通过此配置避免向istio-proxy中注入
instrumentation.opentelemetry.io/container-names: "myapp,myapp2"

NodeJS:

instrumentation.opentelemetry.io/inject-nodejs: "true"

Python:

instrumentation.opentelemetry.io/inject-python: "true"

.NET:

.NET auto-instrumentation also honors an annotation that will be used to set the .NET Runtime Identifiers(RIDs). Currently, only two RIDs are supported: linux-x64 and linux-musl-x64. By default linux-x64 is used.

instrumentation.opentelemetry.io/inject-dotnet: "true"
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-x64" # for Linux glibc based images, this is default value and can be omitted
instrumentation.opentelemetry.io/otel-dotnet-auto-runtime: "linux-musl-x64"  # for Linux musl based images

Go:

Go auto-instrumentation also honors an annotation that will be used to set the OTEL_GO_AUTO_TARGET_EXE env var. This env var can also be set via the Instrumentation resource, with the annotation taking precedence. Since Go auto-instrumentation requires OTEL_GO_AUTO_TARGET_EXE to be set, you must supply a valid executable path via the annotation or the Instrumentation resource. Failure to set this value causes instrumentation injection to abort, leaving the original pod unchanged.

instrumentation.opentelemetry.io/inject-go: "true"
instrumentation.opentelemetry.io/otel-go-auto-target-exe: "/path/to/container/executable"

Go auto-instrumentation also requires elevated permissions. The below permissions are set automatically and are required.

securityContext:privileged: truerunAsUser: 0

Apache HTTPD:

instrumentation.opentelemetry.io/inject-apache-httpd: "true"

Nginx:

instrumentation.opentelemetry.io/inject-nginx: "true"

OpenTelemetry SDK environment variables only:

instrumentation.opentelemetry.io/inject-sdk: "true"

可选值:

  • true - inject and Instrumentation resource from the namespace.
  • my-instrumentation - name of Instrumentation CR instance in the current namespace.
  • my-other-namespace/my-instrumentation - name and namespace of Instrumentation CR instance in another namespace.
  • false - do not inject
3.3.3 Pod内多个container注入
apiVersion: apps/v1
kind: Deployment
metadata:name: my-deployment-with-multi-containers-multi-instrumentations
spec:selector:matchLabels:app: my-pod-with-multi-containers-multi-instrumentationsreplicas: 1template:metadata:labels:app: my-pod-with-multi-containers-multi-instrumentationsannotations:instrumentation.opentelemetry.io/inject-java: "true"instrumentation.opentelemetry.io/java-container-names: "myapp,myapp2"instrumentation.opentelemetry.io/inject-python: "true"instrumentation.opentelemetry.io/python-container-names: "myapp3"spec:containers:- name: myappimage: myImage1- name: myapp2image: myImage2- name: myapp3image: myImage3
3.3.4 Java Pod自动注入

Java Pod被OTel自动注入后,Pod定义被修改如下:

apiVersion: v1
kind: Pod
metadata:labels:app: app-atomversion: v1name: app-atom-6c97b8dd84-mw222namespace: otel-poc
spec:containers:- env:- name: SPRING_OUTPUT_ANSI_ENABLEDvalue: NEVER- name: LOGGING_CONFIGvalue: /config/logback-spring.xml- name: JAVA_TOOL_OPTIONSvalue: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar'- name: OTEL_SERVICE_NAMEvalue: app-atom- name: OTEL_EXPORTER_OTLP_ENDPOINTvalue: http://otel-collector.opentelemetry-operator-system.svc.cluster.local:4317- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAMEvalueFrom:fieldRef:apiVersion: v1fieldPath: metadata.name- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAMEvalueFrom:fieldRef:apiVersion: v1fieldPath: spec.nodeName- name: OTEL_PROPAGATORSvalue: tracecontext,baggage,b3- name: OTEL_TRACES_SAMPLERvalue: parentbased_traceidratio- name: OTEL_TRACES_SAMPLER_ARGvalue: "0.25"- name: OTEL_RESOURCE_ATTRIBUTESvalue: k8s.container.name=app-atom,k8s.deployment.name=app-atom,k8s.namespace.name=otel-poc,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME),k8s.replicaset.name=app-atom-6c97b8dd84,service.version=latestimage: otel-poc/app-atom:latestimagePullPolicy: IfNotPresentlivenessProbe:failureThreshold: 3httpGet:path: /actuator/healthport: 8080scheme: HTTPinitialDelaySeconds: 60periodSeconds: 10successThreshold: 1timeoutSeconds: 5name: app-atomports:- containerPort: 8080name: httpprotocol: TCP- containerPort: 9999name: http-xxljobprotocol: TCPreadinessProbe:failureThreshold: 3httpGet:path: /actuator/healthport: 8080scheme: HTTPinitialDelaySeconds: 60periodSeconds: 10successThreshold: 1timeoutSeconds: 5resources:limits:cpu: "1"memory: 1000Mirequests:cpu: 10mmemory: 128MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /config/name: app-config- mountPath: /var/run/secrets/kubernetes.io/serviceaccountname: kube-api-access-vxx27readOnly: true- mountPath: /otel-auto-instrumentation-javaname: opentelemetry-auto-instrumentation-javadnsPolicy: ClusterFirstenableServiceLinks: trueinitContainers:- command:- cp- /javaagent.jar- /otel-auto-instrumentation-java/javaagent.jarimage: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:231128imagePullPolicy: IfNotPresentname: opentelemetry-auto-instrumentation-javaresources:limits:cpu: 500mmemory: 64Mirequests:cpu: 50mmemory: 64MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /otel-auto-instrumentation-javaname: opentelemetry-auto-instrumentation-java- mountPath: /var/run/secrets/kubernetes.io/serviceaccountname: kube-api-access-vxx27readOnly: truenodeName: k-node1preemptionPolicy: PreemptLowerPrioritypriority: 0restartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}serviceAccount: defaultserviceAccountName: defaultterminationGracePeriodSeconds: 30tolerations:- effect: NoExecutekey: node.kubernetes.io/not-readyoperator: ExiststolerationSeconds: 300- effect: NoExecutekey: node.kubernetes.io/unreachableoperator: ExiststolerationSeconds: 300volumes:- configMap:defaultMode: 420name: app-atomname: app-config- name: kube-api-access-vxx27projected:defaultMode: 420sources:- serviceAccountToken:expirationSeconds: 3607path: token- configMap:items:- key: ca.crtpath: ca.crtname: kube-root-ca.crt- downwardAPI:items:- fieldRef:apiVersion: v1fieldPath: metadata.namespacepath: namespace- emptyDir:sizeLimit: 200Miname: opentelemetry-auto-instrumentation-java
3.3.5 剔除/actuator/health

https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1060
在这里插入图片描述


参考:
https://opentelemetry.io/docs/kubernetes/
https://opentelemetry.io/docs/kubernetes/operator/
https://github.com/open-telemetry/opentelemetry-helm-charts
https://github.com/open-telemetry/opentelemetry-operator
阿里技术 - 深入浅出eBPF|你要了解的7个核心问题

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/239266.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

表的创建和管理

表的创建和管理 一条数据的存储过程标识符的命名规则MySQL中的数据类型管理和创建数据库创建数据库使用数据库修改数据库 创建表创建方式1创建方式2查看数据表结构 修改表追加一个列修改一个列重命名一个列删除一个列 重命名表删除表清空表 一条数据的存储过程 存储数据是处理数…

配置中心--Spring Cloud Config

概述 因为微服务架构有很多个服务&#xff0c;手动一个一个管理各个服务配置很麻烦&#xff0c;不同的环境&#xff08;开发、测试、生产&#xff09;往往需要不同的配置文件&#xff0c;运行期间也需要动态调整配置&#xff0c;修改配置后微服务需要自动更新配置&#xff0c;…

从“芯”到云,看亚马逊云科技如何让未来“平等”发生

文章目录 业界最全面算力选择&#xff0c;有效解决多样性需求多年自研芯片积累&#xff0c;带来性能与性价比双重优势全球基础设施与独特的业务模式&#xff0c;让创新不受限 “科幻作家威廉吉布森说‘未来已至&#xff0c;只是还没有均匀分布’。”2023年6月底&#xff0c;当亚…

C语言实现猜数字游戏

前面我们已经了解了分支循环、数据类型及变量的知识点&#xff0c;今天我将用之前学过的知识进行实操&#xff0c;将所学的知识进行巩固和提升。下面的讲解仅我个人认知水平&#xff0c;如有欠缺之处&#xff0c;欢迎大家指正&#xff0c;并且我希望初学者在看完讲解后可以独立…

spring boot 3.2.0 idea从零开始

spring boot 3.2.0 idea从零开始 最新的spring initilizer 不再支持低版本java&#xff0c;只能选择17、21 。 我也被迫尝试下最新版本的java。 jdk下载地址 自定义好artifact和group之后点击下一步。 在这里选择需要的组件&#xff0c;我准备做web项目所以只选择spring web …

智慧工地平台源码,支持多端展示:PC端、手机端、平板端,实现数据同步

智慧工地源码&#xff0c;微服务架构JavaSpring Cloud UniApp MySql&#xff1b; 依托组件化开发平台&#xff0c;支持多端展示&#xff1a;PC端、手机端、平板端&#xff0c;实现数据同步&#xff1b; 智慧工地平台主要利用智能终端、物联网、移动互联等技术&#xff0c;实时采…

【LeetCode:1094. 拼车 | 差分数组】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…

最长连续递增序列

最长连续递增序列 描述 : 给定一个未经排序的整数数组&#xff0c;找到最长且 连续递增的子序列&#xff0c;并返回该序列的长度。 连续递增的子序列 可以由两个下标 l 和 r&#xff08;l < r&#xff09;确定&#xff0c;如果对于每个 l < i < r&#xff0c;都有 …

C/C++,图算法——求强联通的Tarjan算法之源程序

1 文本格式 #include <bits/stdc.h> using namespace std; const int maxn 1e4 5; const int maxk 5005; int n, k; int id[maxn][5]; char s[maxn][5][5], ans[maxk]; bool vis[maxn]; struct Edge { int v, nxt; } e[maxn * 100]; int head[maxn], tot 1; vo…

【学习记录】从0开始的Linux学习之旅——应用开发(helloworld)

一、概述 Linux操作系统通常是基于Linux内核&#xff0c;并结合GNU项目中的工具和应用程序而成。Linux操作系统支持多用户、多任务和多线程&#xff0c;具有强大的网络功能和良好的兼容性。本文主要讲述如何在linux系统上进行应用开发。 二、概念及原理 应用程序通过系统调用与…

JS 实现一键复制文本内容

1、演示&#xff1a; 2、代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>一键复制</title&g…

机器学习---EM算法

1. 极大似然估计与EM算法 极大似然估计是一种常用的参数估计方法&#xff0c;它是以观测值出现的概率最大作为准则。关于极 大似然估计&#xff0c;假设现在已经取到样本值了&#xff0c;这表明取到这一样本的概率L(θ) 比较 大。我们自然不会考虑那些不能使样本出现的θ作为…