|
本文档采用自动化机器翻译技术翻译。 尽管我们力求提供准确的译文,但不对翻译内容的完整性、准确性或可靠性作出任何保证。 若出现任何内容不一致情况,请以原始 英文 版本为准,且原始英文版本为权威文本。 |
在 Kubernetes 上开始使用 Open Telemetry
本指南提供了监控应用程序的说明。
-
在集群 A 中运行的被监控应用程序/工作负载。
-
在被观察的应用程序附近运行的 Open Telemetry 收集器,因此在集群 A 中,并将数据发送到 SUSE® Observability。
-
在集群 B 中运行的 SUSE® Observability,或 SUSE Cloud Observability。
Open Telemetry 收集器
|
对于生产环境,强烈建议安装收集器,因为它可以快速卸载数据,并且收集器可以处理额外的操作,如重试、批处理、加密或甚至敏感数据过滤。 |
在集群 A 中安装 OTel(Open Telemetry)收集器并将其配置为:
-
接收来自多个被仪表化应用程序的数据。
-
用 Kubernetes 属性丰富收集的数据。
-
为跟踪生成指标。
-
将数据转发到 SUSE® Observability,包括使用 API 密钥进行身份验证。
| 当出现连接问题时,SUSE® Observability 也会重试发送数据。 |
创建服务令牌
有两种方法可以创建服务令牌:
-
SUSE® Observability UI - 点击屏幕左上角打开主菜单,然后转到
StackPacks>Open Telemetry。 如果您之前没有这样做,请点击INSTALL按钮。点击CREATE NEW SERVICE TOKEN按钮并将值复制到剪贴板。 -
SUSE® Observability CLI - 请参见 管理服务词元
服务令牌值必须在下面的说明中提到 <SERVICE_TOKEN> 的地方使用。
创建名称空间和服务令牌的密钥
在 open-telemetry 名称空间中安装并使用服务令牌:
kubectl create namespace open-telemetry
kubectl create secret generic open-telemetry-collector \
--namespace open-telemetry \
--from-literal=API_KEY='<SERVICE_TOKEN>'
配置并安装收集器
我们使用 Open Telemetry 项目提供的 Helm 图表安装收集器。确保您已配置 Open Telemetry helm 图表库:
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
为 Helm 图表创建一个 otel-collector.yaml 值文件。这是与 SUSE® Observability 使用的一个良好起点,将 <otlp-suse-observability-endpoint:port> 替换为您的 OTLP 端点(请参见 OTLP API 获取您的端点),并将您的 Kubernetes 集群名称插入 <your-cluster-name> 位置:
# Set the API key from the secret as an env var:
extraEnvsFrom:
- secretRef:
name: open-telemetry-collector
mode: deployment
image:
# Use the collector container image that has all components important for k8s. In case of missing components the ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib image can be used which
# has all components in the contrib repository: https://github.com/open-telemetry/opentelemetry-collector-contrib
repository: "ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s"
ports:
metrics:
enabled: true
presets:
kubernetesAttributes:
enabled: true
extractAllPodLabels: true
# This is the config file for the collector:
config:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
# Scrape the collectors own metrics
prometheus:
config:
scrape_configs:
- job_name: opentelemetry-collector
scrape_interval: 10s
static_configs:
- targets:
- ${env:MY_POD_IP}:8888
extensions:
# Use the API key from the env for authentication
bearertokenauth:
scheme: SUSEObservability
token: "${env:API_KEY}"
exporters:
nop: {}
otlp/suse-observability:
auth:
authenticator: bearertokenauth
# Put in your own otlp endpoint, for example otlp-suse-observability.my.company.com:443
endpoint: <otlp-suse-observability-endpoint:port>
compression: snappy
processors:
memory_limiter:
check_interval: 5s
limit_percentage: 80
spike_limit_percentage: 25
batch: {}
resource:
attributes:
- key: k8s.cluster.name
action: upsert
# Insert your own cluster name
value: <your-cluster-name>
- key: service.instance.id
from_attribute: k8s.pod.uid
action: insert
# Use the k8s namespace also as the open telemetry namespace
- key: service.namespace
from_attribute: k8s.namespace.name
action: insert
connectors:
# Generate metrics for spans
spanmetrics:
metrics_expiration: 5m
namespace: otel_span
service:
extensions: [ health_check, bearertokenauth ]
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, resource, batch]
exporters: [debug, spanmetrics, otlp/suse-observability]
metrics:
receivers: [otlp, spanmetrics, prometheus]
processors: [memory_limiter, resource, batch]
exporters: [debug, otlp/suse-observability]
logs:
receivers: [otlp]
processors: []
exporters: [nop]
telemetry:
metrics:
address: ${env:MY_POD_IP}:8888
|
使用与安装 SUSE® Observability 代理相同的集群名称,如果您还使用 Kubernetes stackpack 的 SUSE® Observability 代理。使用不同的集群名称将导致 Kubernetes 组件的跟踪视角为空,并且总体上会使 SUSE® Observability 和您的用户之间的信息关联变得更加困难。 |
使用配置文件安装收集器:
helm upgrade --install opentelemetry-collector open-telemetry/opentelemetry-collector \
--values otel-collector.yaml \
--namespace open-telemetry
从您的应用程序收集遥测数据
收集遥测数据的常见方法是使用 Open Telemetry SDK 对您的应用程序进行遥测仪表化。
对于其他语言,请遵循 opentelemetry.io 上的文档,并确保按照 这些说明 配置 SDK 导出器以将数据发送到您刚刚安装的收集器。
Rancher RBAC
为了使 Rancher RBAC 工作,遥测数据需要具有以下资源属性:
-
k8s.cluster.name- Kubernetes stackpack 使用的 集群 名称 -
k8s.namespace.name- Rancher 项目 管理的 名称空间
这可以通过上述配置实现。 在这里,kubernetesAttributes 预设的 opentelemetry-collector Helm 图表将 k8sattributes 处理器注入到每个管道中。