【发布时间】:2018-10-15 04:26:28
【问题描述】:
我们希望我们的 Prometheus 安装能够抓取 pod 中两个容器的指标。
一个容器通过 HTTPS 在端口 443 公开指标,而另一个容器通过 HTTP 在端口 8080 公开指标。两个容器在同一路径上提供指标,即/metrics。
如果我们将 prometheus.io/scheme 声明为 http 或 https,则只会抓取一个容器。对于另一个我们总是收到:server returned HTTP status 400 Bad Request
如果我们根本不定义 prometheus.io/scheme,也会发生同样的情况。然后,Prometheus 将对两个端口都使用 http,而在 443 端口公开指标的容器会失败,因为它只需要 HTTPS 请求。
有没有办法告诉 prometheus 它应该如何准确地抓取我们部署中的各个容器?获取两个容器的指标的可行解决方法是什么?
版本
Kubernetes:1.10.2
普罗米修斯:2.2.1
部署摘录
apiVersion: apps/v1
kind: Deployment
metadata:
name: xxx
namespace: xxx
spec:
selector:
matchLabels:
app: xxx
template:
metadata:
labels:
app: xxx
annotations:
prometheus.io/scrape: "true"
prometheus.io/path: "/metrics"
spec:
containers:
- name: container-1
image: xxx
ports:
- containerPort: 443
- name: container-2
image: xxx
ports:
- containerPort: 8080
Prometheus 配置:
- job_name: kubernetes-pods
scrape_interval: 1m
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
kubernetes_sd_configs:
- api_server: null
role: pod
namespaces:
names: []
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
separator: ;
regex: "true"
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
separator: ;
regex: (.+)
target_label: __metrics_path__
replacement: $1
action: replace
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
separator: ;
regex: ([^:]+)(?::\d+)?;(\d+)
target_label: __address__
replacement: $1:$2
action: replace
- separator: ;
regex: __meta_kubernetes_pod_label_(.+)
replacement: $1
action: labelmap
- source_labels: [__meta_kubernetes_namespace]
separator: ;
regex: (.*)
target_label: kubernetes_namespace
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_pod_name]
separator: ;
regex: (.*)
target_label: kubernetes_pod_name
replacement: $1
action: replace
【问题讨论】:
-
您是否考虑过使用边车容器(例如
haproxy)来平滑当前两个容器之间的协议不平衡?我认为您可以将 sidecar 容器命名为container-1,将当前的container-1更改为其他名称,然后(来自 Prometheus 的 PoV)指标将以正确的名称出现,只有您会知道诡计。我在discovery source 中没有看到任何允许您描述的细粒度控制的内容 -
嗨,马修。我们可以做到这一点,事实上,在我们的大多数场景中,两个容器之一已经是卸载 TLS 流量的 sidecar。或多或少,我们已经有一个解决方法可以做到这一点,并从 443 中抓取所有指标。我们仍然有其他星座,我们希望阻止部署另一个边车
标签: kubernetes prometheus