prometheus open /prometheus/queries.active: permission denied

问题描述:

level=info ts=2021-06-28T03:37:41.166Z caller=main.go:331 msg="Starting Prometheus" version="(version=2.16.0, branch=HEAD, revision=b90be6f32a33c03163d700e1452b54454ddce0ec)"
level=info ts=2021-06-28T03:37:41.166Z caller=main.go:332 build_context="(go=go1.13.8, user=root@7ea0ae865f12, date=20200213-23:50:02)"
level=info ts=2021-06-28T03:37:41.166Z caller=main.go:333 host_details="(Linux 4.18.0-240.8.1.el8_3.x86_64 #1 SMP Fri Dec 4 12:24:03 EST 2020 x86_64 prometheus-77f68d86db-cqxx7 (none))"
level=info ts=2021-06-28T03:37:41.166Z caller=main.go:334 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2021-06-28T03:37:41.166Z caller=main.go:335 vm_limits="(soft=unlimited, hard=unlimited)"
level=error ts=2021-06-28T03:37:41.167Z caller=query_logger.go:87 component=activeQueryTracker msg="Error opening query log file" file=/prometheus/queries.active err="open /prometheus/queries.active: permission denied"
panic: Unable to create mmap-ed active query log

goroutine 1 [running]:
github.com/prometheus/prometheus/promql.NewActiveQueryTracker(0x7ffc9bc1ec5b, 0xb, 0x14, 0x2c90040, 0xc00077b350, 0x2c90040)
    /app/promql/query_logger.go:117 +0x4cd
main.main()
    /app/cmd/prometheus/main.go:362 +0x5243

原因: 权限问题,prometheus 的镜像中是使用的 nobody 这个用户,通过 hostPath 挂载到宿主机上面的目录的 ownership 是 root
解决: 在Pod 设置下设置安全上下文

……
securityContext:
  runAsUser: 0
volumes:
- name: data
  hostPath:
    path: /data/prometheus/
- configMap:
    name: prometheus-config
  name: config-volume

你可能感兴趣的:(prometheus open /prometheus/queries.active: permission denied)