You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Kubernetes集群中配置OpenTelemetry Collector通过Proxy对接Exporter

为Kubernetes中的Exporter配置Proxy访问

1. 直接在Exporter的Deployment中添加Proxy环境变量

绝大多数Exporter(如Node Exporter、Blackbox Exporter等)会读取系统级Proxy环境变量,你可以在Deployment的spec.containers.env字段中添加以下配置:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-exporter-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: your-exporter
  template:
    metadata:
      labels:
        app: your-exporter
    spec:
      containers:
      - name: your-exporter
        image: your-exporter-image:tag
        env:
        - name: HTTP_PROXY
          value: "http://your-proxy-ip:port"
        - name: HTTPS_PROXY
          value: "http://your-proxy-ip:port"
        - name: NO_PROXY
          value: "localhost,127.0.0.1,cluster.local,.svc,.local"
  • HTTP_PROXY/HTTPS_PROXY:填写你的Proxy服务器地址和端口
  • NO_PROXY:列出无需走Proxy的地址,比如集群内部服务域名、本地回环地址,避免Exporter访问集群内部资源时走Proxy

2. 使用ConfigMap统一管理Proxy配置

如果多个Exporter需要复用相同的Proxy配置,可将Proxy变量存入ConfigMap,再在Deployment中引用:

创建Proxy配置的ConfigMap

kubectl create configmap proxy-config --from-literal=HTTP_PROXY=http://your-proxy-ip:port --from-literal=HTTPS_PROXY=http://your-proxy-ip:port --from-literal=NO_PROXY="localhost,127.0.0.1,cluster.local,.svc,.local"

在Exporter Deployment中引用ConfigMap

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-exporter-deployment
spec:
  # 省略其他基础配置
  template:
    spec:
      containers:
      - name: your-exporter
        image: your-exporter-image:tag
        envFrom:
        - configMapRef:
            name: proxy-config

3. 针对Prometheus Operator管理的Exporter

若你的Exporter通过Prometheus Operator的ServiceMonitor或PodMonitor管理,直接在对应Exporter的Pod模板中添加上述Proxy环境变量即可。以Blackbox Exporter为例,修改其Deployment的环境变量配置后,Exporter发起外部探测请求时会自动使用指定Proxy。

验证配置有效性

进入Exporter的Pod,执行curl命令测试外部访问:

kubectl exec -it your-exporter-pod-name -- curl -v https://www.example.com

查看输出日志中是否存在Proxy连接记录,以此确认配置生效。

内容的提问来源于stack exchange,提问作者Luis Serrano

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 21:37:06