使用 Prometheus 操作符使用基本身份验证或 TLS 保护 Prometheus 抓取端点

问题描述 投票:0回答:1

我想保护 Prometheus 的不同部分,例如 Prometheus /metrics 和 node-exporter /metrics,或者端点可能是。因此,如果有人要访问该端点,他们将需要证书或用户名和密码。

如何使用 Prometheus 运算符保护这些端点以及如何使用 Prometheus 对其进行身份验证?

我初步了解了 Prometheus 文档,但没有太多关于使用 Prometheus 运算符的信息。我已经使用 basicauth 创建了一个 Configmap,并使用了一个卷挂载到 /etc/prometheus/web_config/web-config.yml 但这似乎破坏了 Prometheus。

任何帮助将不胜感激。

查看文档和 github。

kubernetes devops prometheus monitoring prometheus-operator
1个回答
0
投票

要使用 Prometheus Operator 保护 Prometheus 中的端点,您可以按照以下一般步骤配置身份验证和授权:

  1. 通过创建一个将 basicAuth 字段设置为 true 的 ServiceMonitor,在 Prometheus Operator 中启用身份验证和授权。

  2. 创建一个包含身份验证凭据的 Secret。 Secret 应该有一个用户名密钥和一个密码密钥。

  3. 通过在 Prometheus 配置文件中添加 remote_write 部分,将 Prometheus 实例配置为使用身份验证 Secret。此部分应包含 basic_auth 字段的身份验证信息。

这里是一个 ServiceMonitor 示例,它为 Prometheus 实例启用基本身份验证和授权:


apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app: prometheus
  endpoints:
  - interval: 15s
    port: web
    scheme: http
    basicAuth:
      secretName: prometheus-basic-auth
      usernameKey: username
      passwordKey: password

在本例中,使用名为 prometheus-basic-auth 的 Secret 进行身份验证,密钥为用户名和密码。 ServiceMonitor 应用到带有 app: prometheus 标签的 Prometheus 实例。

请注意,您需要事先创建包含用户名和密码的 Secret。

一旦您配置了 ServiceMonitor,您可以通过将以下部分添加到您的 Prometheus 配置文件来配置 Prometheus 以对 /metrics 端点使用身份验证:


remote_write:
  - url: "http://your-prometheus-url/write"
    basic_auth:
      username: "your-username"
      password: "your-password"

确保用适当的值替换 your-prometheus-url、your-username 和 your-password。

您还可以将类似的配置应用于其他端点,例如节点导出器端点。

请记住,保护端点可能会影响您的 Prometheus 实例和监控系统的性能,因此在实施这些更改后测试和监控系统非常重要。

© www.soinside.com 2019 - 2024. All rights reserved.