接入 Istio

最近更新时间:2025-11-18 15:28:21

我的收藏
Istio 已内置分布式链路追踪能力,通过简单的配置就能将部署在服务网格的应用接入到应用性能监控 APM,关于 Istio 的更多详情,请参考 Istio 官方文档。Istio 基于 Envoy 实现链路数据采集与上报,请参考 Envoy 官方文档

前提条件

Kubernetes 集群已经安装 Istio,且 Istio 版本在1.19及以上。

接入步骤

步骤1:获取接入点和 token

1. 登录 腾讯云可观测平台 控制台。
2. 在左侧菜单栏中选择应用性能监控 > 应用列表,单击接入应用
3. 选择接入其他应用
4. 选择您所要接入的地域以及业务系统
5. 选择您所想要的上报方式,获取接入点和 Token。
说明:
内网上报:使用此上报方式,您的服务需运行在腾讯云 VPC。通过 VPC 直接连通,在避免外网通信的安全风险同时,可以节省上报流量开销。
外网上报:当您的服务部署在本地或非腾讯云 VPC 内,可以通过此方式上报数据。请注意外网通信存在安全风险,同时也会造成一定上报流量费用。

步骤2:安装 OpenTelemetry Collector

Istio 上报的链路数据需要通过 OpenTelemetry Collector 转发到应用性能监控 APM。如果 Kubernetes 集群尚未安装 OpenTelemetry Collector,请参考该步骤完成安装。如果 Kubernetes 集群已经安装 OpenTelemetry Collector,请参考该步骤调整接入点和 Token 信息。
1. 编写部署描述文件 otel.yaml,并将 ConfigMap 中的 opentelemetry-collector-config.exporters.otlp.endpoint 字段和 opentelemetry-collector-config.exporters.otlp.endpoint 字段设置为 步骤1 拿到的接入点和 Token。
cat > otel.yaml <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: opentelemetry-collector-conf
labels:
app: opentelemetry-collector
data:
opentelemetry-collector-config:
receivers:
otlp:
protocols:
grpc:
http:
processors:
batch:
exporters:
otlp:
endpoint: "<APM-Endpoint>" # Replace <APM-Endpoint> with the access point obtained in the previous step
headers:
authorization: "<APM-Token>" # Replace <APM-Token> with the token obtained in the previous step
tls:
insecure: true
logging:
loglevel: debug
extensions:
health_check:
port: 13133
service:
extensions:
- health_check
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
traces:
receivers:
- otlp
exporters:
- logging
- otlp
---
apiVersion: v1
kind: Service
metadata:
name: opentelemetry-collector
labels:
app: opentelemetry-collector
spec:
ports:
- name: grpc-opencensus
port: 55678
protocol: TCP
targetPort: 55678
- name: grpc-otlp # Default endpoint for OpenTelemetry receiver.
port: 4319
protocol: TCP
targetPort: 4319
- name: http-otlp # HTTP endpoint for OpenTelemetry receiver.
port: 4318
protocol: TCP
targetPort: 4318
selector:
app: opentelemetry-collector
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: opentelemetry-collector
spec:
selector:
matchLabels:
app: opentelemetry-collector
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: opentelemetry-collector
sidecar.istio.io/inject: "false" # do not inject
spec:
containers:
- command:
- "/otelcol"
- "--config=/conf/opentelemetry-collector-config.yaml"
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
image: otel/opentelemetry-collector:0.54.0
imagePullPolicy: IfNotPresent
name: opentelemetry-collector
ports:
- containerPort: 4319
protocol: TCP
- containerPort: 4318
protocol: TCP
- name: grpc-opencensus
containerPort: 55678
protocol: TCP
resources:
limits:
cpu: "2"
memory: 4Gi
requests:
cpu: 200m
memory: 400Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- name: opentelemetry-collector-config-vol
mountPath: /conf
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
items:
- key: opentelemetry-collector-config
path: opentelemetry-collector-config.yaml
name: opentelemetry-collector-conf
name: opentelemetry-collector-config-vol
EOF
2. 创建 observability 命名空间。
kubectl create namespace observability
3. 将 OpenTelemetry Collector 部署到 observability 命名空间。
kubectl apply -f otel.yaml -n observability

步骤3:配置 Istio 链路追踪

1. 在集群中运行以下命令,允许 Istio 将链路数据通过 OpenTelemetry 协议发送到集群中部署的 OpenTelemetry Collector。
cat <<EOF | istioctl install -y -f -
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
meshConfig:
defaultConfig:
tracingServiceName: CANONICAL_NAME_ONLY
enableTracing: true
extensionProviders:
- name: otel-tracing
opentelemetry:
port: 4319
service: opentelemetry-collector.observability.svc.cluster.local
resource_detectors:
environment: {}
EOF
说明:
Istio 提供了配置选项tracingServiceName来控制应用名称的生成方式。在 APM 中,多个使用相同应用名称接入的应用进程,会表现为相同应用下的多个实例。tracingServiceName有三种选项:
APP_LABEL_AND_NAMESPACE(默认值):使用 <app 标签>.<命名空间> 格式。
CANONICAL_NAME_ONLY:仅使用工作负载的规范名称,如 Deployment 的名称。
CANONICAL_NAME_AND_NAMESPACE:使用 <规范名称>.<命名空间> 格式。
2. 运行以下命令启用 Istio 链路追踪。
kubectl apply -f - <<EOF
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: otel-demo
namespace: istio-system
spec:
tracing:
- providers:
- name: otel-tracing
randomSamplingPercentage: 100
EOF
说明:
通过调整 Telemetry 资源的配置,可以灵活指定开启链路追踪的工作负载的范围,主要包括如下几种策略:
整个服务网络:本文的示例使用该策略,代表整个服务网络中的业务工作负载都开启链路追踪。
指定命名空间。
指定工作负载。
更多配置详情,请参考 Istio Telemetry API

接入验证

在应用有正常流量的情况下,应用性能监控 > 应用列表 中将展示接入的应用。单击应用名称/ID 进入应用详情页,再选择实例分析,即可看到接入的应用实例。由于可观测数据的处理存在一定延时,如果接入后在控制台没有查询到应用或实例,请等待30秒左右。