Prometheus 监控 Kubernetes 服务的配置说明
Kubernetes SD 配置项可以通过Kubernetes 的REST API 发现不同的数据采集目标,并和集群的状态保持同步。
Role 类型用于配置发现的目标类型。
一、node角色
Node 角色用于发现集群的节点,使用Kubelet 服务的Http端口为默认地址。
目标地址默认为kubernetes节点对象的第一个现有地址,地址类型顺序为nodeInternalip、nodeExternalip、nodelegacychostip和nodehostname。
允许的元标签:
- __meta_kubernetes_node_name: node 节点的名词
- __meta_kubernetes_node_label_<labelname>: node 节点的标签
- __meta_kubernetes_node_labelpresent_<labelname>: 对于来自节点对象的每个标签为true。
- __meta_kubernetes_node_annotation_<annotationname>: 节点对象中的每个注释。
- __meta_kubernetes_node_annotationpresent_<annotationname>: 对于来自节点对象的每个注释为true。
- __meta_kubernetes_node_address_<address_type>: 每个节点地址类型的第一个地址(如果存在)。
此外,该节点的实例标签将设置为从API服务器检索到的节点名称。
二、service
Service角色用于发现每个服务的每个服务端口。
这对于服务的黑盒监控通常很有用。地址将设置为服务的kubernetes DNS名称和相应的服务端口。
允许的元标签:
- __meta_kubernetes_namespace: 服务的namespace对象
- __meta_kubernetes_service_annotation_<annotationname>: 服务对象中的每个注释。
- __meta_kubernetes_service_annotationpresent_<annotationname>: 服务对象的每个注释都为“true”。
- __meta_kubernetes_service_cluster_ip: 服务的群集IP地址。(不适用于ExternalName类型的服务)
- __meta_kubernetes_service_external_name: 服务的DNS名称。(适用于externalname类型的服务)
- __meta_kubernetes_service_label_<labelname>: 服务对象中的每个标签。
- __meta_kubernetes_service_labelpresent_<labelname>: 对于服务对象的每个标签都为true。
- __meta_kubernetes_service_name: 服务对象的名称。
- __meta_kubernetes_service_port_name: 目标的服务端口的名称。
- __meta_kubernetes_service_port_number: 目标的服务端口号。
- __meta_kubernetes_service_port_protocol: 目标服务端口的协议。
三、pod
pod角色发现所有pod对象和容器。
对于容器的每个声明端口,将生成单个目标。如果容器没有指定端口,则为每个容器创建一个无端口目标,用于通过重新标记手动添加端口。
允许的元标签:
- __meta_kubernetes_namespace: pod对象的命名空间。
- __meta_kubernetes_pod_name: pod对象的名称。
- __meta_kubernetes_pod_ip: pod对象的pod ip。
- __meta_kubernetes_pod_label_<labelname>: pod对象的每个标签。
- __meta_kubernetes_pod_labelpresent_<labelname>: 对于pod对象中的每个标签都为true。
- __meta_kubernetes_pod_annotation_<annotationname>: pod对象的每个注释。
- __meta_kubernetes_pod_annotationpresent_<annotationname>: 对于pod对象中的每个注释都为true。
- __meta_kubernetes_pod_container_init: 如果容器是initcontainer,则为true
- __meta_kubernetes_pod_container_name: 目标地址指向的容器的名称。
- __meta_kubernetes_pod_container_port_name: Name of the container port.
- __meta_kubernetes_pod_container_port_number: Number of the container port.
- __meta_kubernetes_pod_container_port_protocol: Protocol of the container port.
- __meta_kubernetes_pod_ready: Set to true or false for the pod’s ready state.
- __meta_kubernetes_pod_phase: Set to Pending, Running, Succeeded, Failed or Unknown in the lifecycle.
- __meta_kubernetes_pod_node_name: The name of the node the pod is scheduled onto.
- __meta_kubernetes_pod_host_ip: The current host IP of the pod object.
- __meta_kubernetes_pod_uid: The UID of the pod object.
- __meta_kubernetes_pod_controller_kind: Object kind of the pod controller.
- __meta_kubernetes_pod_controller_name: Name of the pod controller.
四、endpoints
端点角色从列出的服务端点发现目标。
对于每个端点地址,每个端口发现一个目标。如果端点由POD支持,则POD的所有附加容器端口(未绑定到端点端口)也将被发现为目标。
允许的元标签:
- __meta_kubernetes_namespace: The namespace of the endpoints object.
- __meta_kubernetes_endpoints_name: The names of the endpoints object.
对于直接从Endpoints列表中发现的所有目标(未从基础pods中额外推断的目标),将附加以下标签:
- __meta_kubernetes_endpoint_hostname: Hostname of the endpoint.
- __meta_kubernetes_endpoint_node_name: Name of the node hosting the endpoint.
- __meta_kubernetes_endpoint_ready: Set to true or false for the endpoint’s ready state.
- __meta_kubernetes_endpoint_port_name: Name of the endpoint port.
- __meta_kubernetes_endpoint_port_protocol: Protocol of the endpoint port.
- __meta_kubernetes_endpoint_address_target_kind: Kind of the endpoint address target.
- __meta_kubernetes_endpoint_address_target_name: Name of the endpoint address target.
如果Endpoints属于某个服务,则会附加角色的所有标签: service discovery are attached.
对于由一个pod支持的所有目标,将附加角色的所有标签: pod discovery are attached.
五、ingress
ingress角色为发现ingress对象。这对于黑盒监视Ingress通常很有用。地址将设置为Ingress规范中指定的主机。
允许的元标签:
- __meta_kubernetes_namespace: The namespace of the ingress object.
- __meta_kubernetes_ingress_name: The name of the ingress object.
- __meta_kubernetes_ingress_label_<labelname>: Each label from the ingress object.
- __meta_kubernetes_ingress_labelpresent_<labelname>: true for each label from the ingress object.
- __meta_kubernetes_ingress_annotation_<annotationname>: Each annotation from the ingress object.
- __meta_kubernetes_ingress_annotationpresent_<annotationname>: true for each annotation from the ingress object.
- __meta_kubernetes_ingress_scheme: Protocol scheme of ingress, https if TLS config is set. Defaults to http.
- __meta_kubernetes_ingress_path: Path from ingress spec. Defaults to /.
六、访问 Kubernetes API 的连接信息配置
# The API server addresses. If left empty, Prometheus is assumed to run inside
# of the cluster and will discover API servers automatically and use the pod's
# CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
[ api_server: <host> ]
# The Kubernetes role of entities that should be discovered.
role: <role>
# Optional authentication information used to authenticate to the API server.
# Note that `basic_auth`, `bearer_token` and `bearer_token_file` options are
# mutually exclusive.
# password and password_file are mutually exclusive.
# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]
# Optional bearer token authentication information.
[ bearer_token: <secret> ]
# Optional bearer token file authentication information.
[ bearer_token_file: <filename> ]
# Optional proxy URL.
[ proxy_url: <string> ]
# TLS configuration.
tls_config:
[ <tls_config> ]
# Optional namespace discovery. If omitted, all namespaces are used.
namespaces:
names:
[ - <string> ]
Where <role> must be endpoints, service, pod, node, or ingress.