简体   繁体   English

Prometheus抓取K8s入口端点

[英]Prometheus to scrape K8s Ingress Endpoints

My Prometheus instance is currently deployed outside to the K8s cluster. 我的Prometheus实例当前已部署到K8s集群的外部。 I went through the below article : https://www.linkedin.com/pulse/monitoring-kubernetes-prometheus-outside-cluster-steven-acreman 我浏览了以下文章: https : //www.linkedin.com/pulse/monitoring-kubernetes-prometheus-outside-cluster-steven-acreman

and this gives a very good idea about accessing the K8s services via the api server. 这为通过api服务器访问K8s服务提供了一个很好的主意。 I am still trying to make it work (stuck with certificates issue). 我仍在尝试使其工作(卡有证书问题)。

However, my question is can't we use Prometheus to scape the ingress-controller hostname to scrape metrics endpoint. 但是,我的问题是我们是否可以使用Prometheus代替入口控制器主机名来刮擦指标端点。 Or is that even a standard approach? 还是那是一种标准方法?

I could not find a single document or implementation around the same. 我找不到相同的单个文档或实现。 Please suggest if anyone has implemented the above scenario or has any docs on it. 请建议是否有人实现了上述方案或上面有任何文档。

I would use Kubernetes SD configurations , and take adventage of roles to discover targets. 我将使用Kubernetes SD配置 ,并冒险使用角色来发现目标。

Kubernetes SD configurations allow retrieving scrape targets from Kubernetes' REST API and always staying synchronized with the cluster state. Kubernetes SD配置允许从Kubernetes的 REST API检索抓取目标,并始终与集群状态保持同步。

You could use role type endpoints : 您可以使用角色类型endpoints

The endpoints role discovers targets from listed endpoints of a service. endpoints角色从列出的服务endpoints中发现目标。 For each endpoint address one target is discovered per port. 对于每个端点地址,每个端口都发现一个目标。 If the endpoint is backed by a pod, all additional container ports of the pod, not bound to an endpoint port, are discovered as targets as well. 如果端点由Pod支持,则该Pod的所有其他未绑定到端点端口的容器端口也将被发现为目标。

Available meta labels: 可用的元标签:

  • __meta_kubernetes_namespace : The namespace of the endpoints object. __meta_kubernetes_namespace :端点对象的名称空间。
  • __meta_kubernetes_endpoints_name : The names of the endpoints object. __meta_kubernetes_endpoints_name :端点对象的名称。
  • For all targets discovered directly from the endpoints list (those not additionally inferred from underlying pods), the following labels are attached: 对于直接从端点列表中发现的所有目标(未从基础容器额外推断出的所有目标),将附加以下标签:
    • __meta_kubernetes_endpoint_hostname : Hostname of the endpoint. __meta_kubernetes_endpoint_hostname :端点的主机名。
    • __meta_kubernetes_endpoint_node_name : Name of the node hosting the endpoint. __meta_kubernetes_endpoint_node_name :承载端点的节点的名称。
    • __meta_kubernetes_endpoint_ready : Set to true or false for the endpoint's ready state. __meta_kubernetes_endpoint_ready :对于端点的就绪状态,设置为truefalse
    • __meta_kubernetes_endpoint_port_name : Name of the endpoint port. __meta_kubernetes_endpoint_port_name :端点端口的名称。
    • __meta_kubernetes_endpoint_port_protocol : Protocol of the endpoint port. __meta_kubernetes_endpoint_port_protocol :端点端口的协议。
    • __meta_kubernetes_endpoint_address_target_kind : Kind of the endpoint address target. __meta_kubernetes_endpoint_address_target_kind :端点地址目标的种类。
    • __meta_kubernetes_endpoint_address_target_name : Name of the endpoint address target. __meta_kubernetes_endpoint_address_target_name :端点地址目标的名称。
  • If the endpoints belong to a service, all labels of the role: service discovery are attached. 如果端点属于服务,则会附加role: service发现的所有标签。
  • For all targets backed by a pod, all labels of the role: pod discovery are attached. 对于由容器支持的所有目标,将附加role: pod所有标签role: pod发现。

Or role type ingress : 或角色类型ingress

The ingress role discovers a target for each path of each ingress. ingress角色发现每个入口的每个路径的目标。 This is generally useful for blackbox monitoring of an ingress. 这通常对黑盒监视入口很有用。 The address will be set to the host specified in the ingress spec. 该地址将设置为入口规范中指定的主机。

Available meta labels: 可用的元标签:

  • __meta_kubernetes_namespace : The namespace of the ingress object. __meta_kubernetes_namespace :入口对象的名称空间。
  • __meta_kubernetes_ingress_name : The name of the ingress object. __meta_kubernetes_ingress_name :入口对象的名称。
  • __meta_kubernetes_ingress_label_<labelname> : Each label from the ingress object. __meta_kubernetes_ingress_label_<labelname> :来自入口对象的每个标签。
  • __meta_kubernetes_ingress_labelpresent_<labelname> : true for each label from the ingress object. __meta_kubernetes_ingress_labelpresent_<labelname> :对于来自入口对象的每个标签,为true
  • __meta_kubernetes_ingress_annotation_<annotationname> : Each annotation from the ingress object. __meta_kubernetes_ingress_annotation_<annotationname> :来自入口对象的每个注释。
  • __meta_kubernetes_ingress_annotationpresent_<annotationname> : true for each annotation from the ingress object. __meta_kubernetes_ingress_annotationpresent_<annotationname> :对于来自入口对象的每个注释为true
  • __meta_kubernetes_ingress_scheme : Protocol scheme of ingress, https if TLS config is set. __meta_kubernetes_ingress_scheme :入口协议方案,如果设置了TLS配置,则为https Defaults to http . 默认为http
  • __meta_kubernetes_ingress_path : Path from ingress spec. __meta_kubernetes_ingress_path :入口规范的路径。 Defaults to / . 默认为/

If you wish to check detailed example of configuring Prometheus for Kubernetes please see this file . 如果您想查看为Kubernetes配置Prometheus的详细示例,请参阅此文件

Also you might be interested in 3rd party Prometheus Operator , which automates the setup of Peometheus on top of Kubernetes. 您可能也对第三方Prometheus Operator感兴趣,它可以自动在Kubernetes上建立Peometheus。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM