普罗米修斯自动发现K8s [英] Prometheus auto discovery K8s
问题描述
有人可以指导K8自动发现的配置. Prometheus服务器在群集之外.我尝试了使用Kubernetes进行服务发现,并且在此讨论
Can someone guide the configuration for auto discover for K8s. The Prometheus server is outside of the cluster. I tried Service Discovery With Kubernetes and someone mentioned in this discussion
我还不是K8s专家,足以在这里解释所有详细信息,但是 从根本上讲,完全有可能在 集群(并且对于冗余跨集群来说是必需的 元监控). cf.
in_cluster
配置选项在 http://prometheus.io/docs/operating/configuration/# kubernetes-sd-configurations-kubernetes_sd_config .如果在外部运行,则需要跳过证书箍.
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.
所以,我做了一个简单的配置
So, I made a simple configuration
- 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"
或其他一些缩进错误
Getting unknown fields in kubernetes_sd_config: api_servers, in_cluster, retry_interval"
or some other indentation errors
在示例配置中,提到ca_file:
.如何从K8s获取该证书文件,或者有什么方法可以指定K8s config
文件(〜/.kube/config)
In sample configuration, they mentioned ca_file:
. How to get that certificate file from K8s or is there any way to specify K8s config
file(~/.kube/config)
推荐答案
通过挖掘我发现的源代码,如果配置中未提供api_server
( discovery/kubernetes/kubernetes.go#L90-L96
).
By digging though the source code I figured out, that Prometheus always uses the in cluster config, if no api_server
is provided in the config (discovery/kubernetes/kubernetes.go#L90-L96
).
以某种方式文档什么也没说Kubernetes配置参数,但源代码可以( api_servers
的列表,而是名称为api_server
的单个参数.
Somehow the docs don't say anything about the Kubernetes configuration parameters, but the source code does (config/config.go#L1026-L1037
). Therefore there is not list named api_servers
, but a single parameter named api_server
.
因此您的配置应如下所示(未试用):
So your config should look like this (untested):
- 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配置的一部分.
I don't know where the retry_interval
parameter comes from, but AFAIK this isn't a Kubernetes config parameter and it's also not part of the Prometheus config.
这篇关于普罗米修斯自动发现K8s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!