【发布时间】:2020-05-06 05:28:39
【问题描述】:
我在本地 kubernetes 集群中部署了 Spring Boot 驱动的微服务。微服务使用 micrometer 和 prometheus 注册表,但由于我们公司的政策,执行器可在另一个端口上使用:
- 8080 用于“业务”http 请求
- 8081/管理执行器。因此,我可以访问
http://host:8081/manage/prometheus并查看在本地运行进程时的指标(没有 kubernetes)。
现在,我是 Prometheus 的初学者,在 kubernetes 方面的知识相当有限(我有 Java 开发人员背景)。
我用我的应用程序创建了一个 POD,并在 kubernetes 中成功运行它。它可以工作,我可以访问它(对于 8080,我创建了一个服务来映射端口),我可以从同一台 PC 执行“业务”级别的 http 请求。
但是我还没有找到任何在图片中添加普罗米修斯的例子。 Prometheus 应该和另一个 pod 一样部署在同一个 Kubernetes 集群中。所以我开始了:
FROM @docker.registry.address@/prom/prometheus:v2.15.2
COPY entrypoint.sh /
USER root
RUN chmod 755 /entrypoint.sh
ADD ./prometheus.yml /etc/prometheus/
ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh 看起来像:
#!/bin/sh
echo "About to run prometheus"
/bin/prometheus --config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus \
--storage.tsdb.retention.time=3d \
--web.console.libraries=/etc/prometheus/console_libraries \
--web.console.templates=/etc/prometheus/consoles
我的问题是我应该如何准确定义 prometheus.yml 以便它从我的 spring boot pod(以及我拥有的其他微服务,所有 spring boot 都使用相同的执行器设置驱动)获取指标。
我从 (prometheus.yml) 开始:
global:
scrape_interval: 10s
evaluation_interval: 10s
scrape_configs:
- job_name: 'prometheus'
metrics_path: /manage/prometheus
kubernetes_sd_configs:
- role: pod
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
action: keep
regex: sample-pod-app(.*)|another-pod-app(.*)
但显然它不起作用,所以我寻求建议:
- 如果有人有一个可行的例子,那将是最好的:)
- 直觉上我知道我需要为我的
8081端口指定端口映射,但我不知道如何 - 既然 prometheus 应该在另一个端口上运行,我是否应该在 kubernetes 级别公开 8081 端口的 kubernetes 服务?
- 我需要在 Kubernetes 中定义任何与安全相关的资源吗?
作为旁注。在这一点上我不关心可扩展性问题,我相信一台 prometheus 服务器可以完成这项工作,但我必须将 Grafana 添加到图片中。
【问题讨论】:
-
也许 devops SE 是问这个问题的好地方
-
是的,可能我没有在那里注册,也许是时候加入我们的战友社区了 :)
标签: java spring spring-boot kubernetes prometheus