首页 > 解决方案 > 远程写入和远程读取的 Prometheus 错误“服务器返回 HTTP 状态 401 未授权”

问题描述

我已经在 Kubernetes 中安装了 Prometheus,我正在尝试对 InfluxDB 使用 remote_write 和 remote_read 选项。我也在数据库中创建了一个具有读写权限的用户。但我收到这样的错误

http://url:port/api/v1/prom/write?db=dbname&u=xxx&p=yyy msg=non-recoverable error" count=100 err="server returned HTTP status 401 Unauthorized: {\"error\":\"authorization failed\"}"

我对普罗米修斯的配置是

 prometheus.yml: |-
global:
  scrape_interval: 5s
  evaluation_interval: 5s
rule_files:
  - /etc/prometheus/prometheus.rules
remote_write:
  - url: "http://url:port/api/v1/prom/write?db=dbname&u=xxxx&p=yyy"
  
remote_read:
  - url: "http://url:port/api/v1/prom/read?db=dbname&u=xxx&p=yyy"

标签: kubernetesgoogle-kubernetes-engineprometheusinfluxdb

解决方案


您可以将您的秘密定义为卷:

 volumeMounts:
    - name: prometheus-secret
      readOnly: true
      mountPath: "/etc/prometheus-secret"

then use it in your prometheus yaml config as:

basic_auth:
   password_file: "/etc/prometheus-secret"

推荐阅读