ZBLOG

k8s:prometheus添加basic_auth_users完整

在Prometheus中添加Basic Authentication(基本认证)用户,可以实现对Prometheus Web UI的访问权限控制。下面是在Kubernetes环境中添加basic_auth_users的完整步骤:

  1. 创建一个htpasswd文件,该文件包含要添加的用户名和密码信息。
  1. htpasswd -c auth <username>
  1. 将生成的auth文件存储为Secret对象。
  1. kubectl create secret generic prometheus-basic-auth --from-file=auth
  1. 编辑Prometheus配置文件prometheus.yaml,在spec.containers.args中增加以下内容:
  1. args:
  2. - '--web.enable-lifecycle'
  3. - '--config.file=/etc/prometheus/prometheus.yml'
  4. - '--storage.tsdb.path=/data/'
  5. - '--web.console.libraries=/usr/share/prometheus/console_libraries'
  6. - '--web.console.templates=/usr/share/prometheus/consoles'
  7. - '--web.external-url=http://localhost:9090/'
  8. + - '--web.auth.basic.user-file=/etc/prometheus/auth'
  9. + - '--web.auth.basic.enabled=true'
  1. 更新Prometheus Deployment对象,将Secret挂载到容器内部,并重启Deployment。
  1. kubectl set volume deployment prometheus-server --add \
  2. --name=prometheus-basic-auth \
  3. --type=secret \
  4. --secret-name=prometheus-basic-auth \
  5. --mount-path /etc/prometheus/
  6. kubectl rollout restart deployment prometheus-server
  1. 确认配置是否生效。在浏览器中访问Prometheus Web UI时会提示输入用户名和密码。

通过以上步骤,我们成功地向Prometheus添加了Basic Authentication用户。这样可以保护我们的监控数据不被未经授权的用户访问和查看。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=4605

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?