gpt4 book ai didi

kubernetes - Prometheus 自动发现 K8s

转载 作者:行者123 更新时间:2023-12-05 00:14:01 25 4
gpt4 key购买 nike

有人可以指导K8s自动发现的配置。 Prometheus 服务器在集群之外。我试过 Service Discovery With Kubernetes并且有人在此 discussion 中提到

I'm not yet a K8s expert enough to explain all the details here, but fundamentally it's perfectly possible to run Prometheus outside of the cluster (and required for things like redundant cross-cluster meta-monitoring). Cf. the in_cluster config option in http://prometheus.io/docs/operating/configuration/#kubernetes-sd-configurations-kubernetes_sd_config . You need to jump through certificate hoops if you run it outside.



所以,我做了一个简单的配置
  - job_name: 'kubernetes'

kubernetes_sd_configs:
-
# The API server addresses. In a cluster this will normally be
# `https://kubernetes.default.svc`. Supports multiple HA API servers.
api_servers:
- https://xxx.xx.xx.xx

# Run in cluster. This will use the automounted CA certificate and bearer
# token file at /var/run/secrets/kubernetes.io/serviceaccount/ in the pod.
in_cluster: false

# Optional HTTP basic authentication information.
basic_auth:
username: prometheus
password: secret

# Retry interval between watches if they disconnect.
retry_interval: 5s

获取 unknown fields in kubernetes_sd_config: api_servers, in_cluster, retry_interval"或其他一些缩进错误

sample configuration ,他们提到了 ca_file: .如何从 K8s 获取该证书文件或者有什么方法可以指定 K8s config文件(~/.kube/config)

最佳答案

通过挖掘我发现的源代码,Prometheus 总是使用集群配置,如果没有 api_server在配置( discovery/kubernetes/kubernetes.go#L90-L96 )中提供。

不知何故 docs不要说 Kubernetes 配置参数,但源代码( config/config.go#L1026-L1037 )。因此没有名为 api_servers 的列表,但有一个名为 api_server 的参数.

所以你的配置应该是这样的(未经测试):

  - job_name: 'kubernetes'

kubernetes_sd_configs:
-
# The API server addresses. In a cluster this will normally be
# `https://kubernetes.default.svc`. Supports multiple HA API servers.
api_server: https://xxx.xx.xx.xx

# Optional HTTP basic authentication information.
basic_auth:
username: prometheus
password: secret

# specify the CA
tls_config:
ca_file: /path/to/ca.crt
## If the actual CA file isn't available you need to disable verification:
# insecure_skip_verify: true

我不知道在哪里 retry_interval参数来自,但 AFAIK 这不是 Kubernetes 配置参数,也不是 Prometheus 配置的一部分。

关于kubernetes - Prometheus 自动发现 K8s,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47682158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com