当前位置:网站首页>Kubernetes service discovery monitoring endpoints
Kubernetes service discovery monitoring endpoints
2022-04-23 17:39:00 【Zhang quandan, Foxconn quality inspector】
monitor Pod
Previous apiserver It's actually a special kind of Endpoints, Now let's also configure a task to specifically discover common types of Endpoint, In fact, that is Service The associated Pod list , Because not all Endpoints Will provide metrics Interface , So we need to take the initiative to tell Prometheus To discover what Endpoints, Of course, there are many ways to tell , But one of the conventional ways is through annotations Note to inform , As shown below :
- job_name: "endpoints"
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
# Retain Service The annotation of is prometheus.io/scrape: true Of Endpoints
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
# The index interface protocol passed prometheus.io/scheme This annotation gets http or https
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
action: replace
target_label: __scheme__
regex: (https?)
# The endpoint path of the index interface passes through prometheus.io/path This annotation gets
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
# The direct interface address port passes through prometheus.io/port Annotation access
- source_labels:
[__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
action: replace
target_label: __address__
regex: ([^:]+)(?::\d+)?;(\d+) # RE2 Regular rule ,+ One or more times ,? yes 0 Time or 1 Time , among ?: Represents a non matching group ( It means not getting matching results )
replacement: $1:$2
# mapping Service Of Label label
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
# take namespace Map to tags
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
# take Service The name is mapped to a label
- source_labels: [__meta_kubernetes_service_name]
action: replace
target_label: kubernetes_name
# take Pod The name is mapped to a label
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
With this annotation , In fact, it is to tell Prometheus, Now the service offers metrics Interface . The port and address provided by the interface must be told , And what the agreement is , All this goes through annotation To provide .
# Retain Service The annotation of is prometheus.io/scrape: true Of Endpoints
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
Notice that we are here relabel_configs
A lot of configuration has been done in the area , Especially the first reservation __meta_kubernetes_service_annotation_prometheus_io_scrape
by true To keep it , This means that you want to automatically discover Endpoint, We need to be in Service Of annotations
Area add prometheus.io/scrape=true
Annotations , We can also use Relabeler - The playground for Prometheus relabeling rules This tool helps us configure Relabel. Now let's update the above configuration , Check the effect :
We can see endpoints
Under this task, only 5 A mission , This is because we are relabel_configs
Filtered annotations
Yes prometheus.io/scrape=true
Of Service, Now only two such services in our system meet the requirements , such as kube-dns
This Service Here are two examples , So there are two examples :
* kubectl get svc kube-dns -n kube-system -o yaml
apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/port: "9153" # metrics Port of the interface
prometheus.io/scrape: "true" # This annotation can make prometheus Auto discovery
creationTimestamp: "2021-10-25T12:33:14Z"
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: CoreDNS
name: kube-dns
namespace: kube-system
......
Now we created before redis This Service To add on prometheus.io/scrape=true
This annotation :
# redis-svc.yaml
kind: Service
apiVersion: v1
metadata:
name: redis
namespace: kube-mon
annotations:
prometheus.io/scrape: "true" # Let the automatic discovery above get the service
prometheus.io/port: "9121" # Appoint metrics Interface access port
spec:
selector:
app: redis
ports:
- name: redis
port: 6379
targetPort: 6379
- name: prom
port: 9121
targetPort: 9121
because redis Service metrics Interface in 9121 This redis-exporter
Service , So we need to add another prometheus.io/port=9121
In this way annotations, Update this Service:
* kubectl apply -f https://p8s.io/docs/k8s/manifests/prometheus/redis-svc.yaml
After the update is complete , Go to Prometheus see Targets route , You can see redis The service automatically appears in endpoints
Under this task :
In this way, we have a new service , If the service itself provides /metrics
Interface , We don't need to configure it statically at all , Now we can put the previously configured redis Static configuration removes .
Empathy prometheus
[[email protected] prometheus]# cat prometheus-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: prometheus
namespace: monitor
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
labels:
app: prometheus
spec:
type: NodePort
ports:
- port: 9090
targetPort: 9090
protocol: TCP
selector:
app: prometheus
component: server
版权声明
本文为[Zhang quandan, Foxconn quality inspector]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231735237233.html
边栏推荐
- 48. 旋转图像
- How to sort the numbers with text in Excel from small to large instead of the first number
- For the space occupation of the software, please refer to the installation directory
- Webapi + form form upload file
- [二叉数] 二叉树的最大深度+N叉树的最大深度
- Use of shell cut command
- Use of todesk remote control software
- Devexpress GridView add select all columns
- [difference between Oracle and MySQL]
- STM32 entry development board choose wildfire or punctual atom?
猜你喜欢
JVM类加载机制
Double pointer advanced -- leetcode title -- container with the most water
flink 学习(十二)Allowed Lateness和 Side Output
索引:手把手教你索引从零基础到精通使用
For the space occupation of the software, please refer to the installation directory
394. 字符串解码-辅助栈
ClickHouse-表引擎
470. Rand10() is implemented with rand7()
JVM class loading mechanism
PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
随机推荐
索引:手把手教你索引从零基础到精通使用
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
Indexes and views in MySQL
Sword finger offer 03 Duplicate number in array
01-初识sketch-sketch优势
一些问题一些问题一些问题一些问题
How to sort the numbers with text in Excel from small to large instead of the first number
Signalr can actively send data from the server to the client
209. Minimum length subarray - sliding window
The system cannot be started after AHCI is enabled
flink 学习(十二)Allowed Lateness和 Side Output
Why do some people say SCM is simple and I have to learn it so hard?
Shell-sort命令的使用
[C] thoroughly understand the deep copy
Header built-in object
XTask与Kotlin Coroutine的使用对比
[ES6] promise related (event loop, macro / micro task, promise, await / await)
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
48. 旋转图像