0%

Prometheus Kubelet ServiceMonitor

1
kubectl get serviceMonitor -n monitoring kubelet -o yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"monitoring.coreos.com/v1","kind":"ServiceMonitor","metadata":{"annotations":{},"labels":{"k8s-app":"kubelet"},"name":"kubelet","namespace":"monitoring"},"spec":{"endpoints":[{"bearerTokenFile":"/var/run/secrets/kubernetes.io/serviceaccount/token","honorLabels":true,"interval":"30s","port":"https-metrics","scheme":"https","tlsConfig":{"insecureSkipVerify":true}},{"bearerTokenFile":"/var/run/secrets/kubernetes.io/serviceaccount/token","honorLabels":true,"interval":"30s","metricRelabelings":[{"action":"drop","regex":"container_(network_tcp_usage_total|network_udp_usage_total|tasks_state|cpu_load_average_10s)","sourceLabels":["__name__"]}],"path":"/metrics/cadvisor","port":"https-metrics","scheme":"https","tlsConfig":{"insecureSkipVerify":true}}],"jobLabel":"k8s-app","namespaceSelector":{"matchNames":["kube-system"]},"selector":{"matchLabels":{"k8s-app":"kubelet"}}}}
creationTimestamp: "2019-12-29T06:40:27Z"
generation: 1
labels:
k8s-app: kubelet
name: kubelet
namespace: monitoring
resourceVersion: "2602"
selfLink: /apis/monitoring.coreos.com/v1/namespaces/monitoring/servicemonitors/kubelet
uid: 327bae9c-d09c-4d00-b293-354870b19f91
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
honorLabels: true
interval: 30s
port: https-metrics
scheme: https
tlsConfig:
insecureSkipVerify: true
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
honorLabels: true
interval: 30s
metricRelabelings:
- action: drop
regex: container_(network_tcp_usage_total|network_udp_usage_total|tasks_state|cpu_load_average_10s)
sourceLabels:
- __name__
path: /metrics/cadvisor
port: https-metrics
scheme: https
tlsConfig:
insecureSkipVerify: true
jobLabel: k8s-app
namespaceSelector:
matchNames:
- kube-system
selector:
matchLabels:
k8s-app: kubelet

根据上面的namespaceSelector和selector

1
kubectl get ep -n kube-system -l k8s-app=kubelet -o yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
apiVersion: v1
items:
- apiVersion: v1
kind: Endpoints
metadata:
creationTimestamp: "2019-12-29T06:40:06Z"
labels:
k8s-app: kubelet
name: kubelet
namespace: kube-system
resourceVersion: "2371"
selfLink: /api/v1/namespaces/kube-system/endpoints/kubelet
uid: 326583cc-3379-4883-8426-5a856c29c77e
subsets:
- addresses:
- ip: 172.16.64.232
targetRef:
kind: Node
name: k8s-node1
uid: 09ffae8e-e3f1-456b-a398-7891487712da
- ip: 172.16.64.233
targetRef:
kind: Node
name: k8s-master
uid: 774ddb3e-2c3c-4af8-8e1c-15b0c2c3b8c1
- ip: 172.16.64.235
targetRef:
kind: Node
name: k8s-node2
uid: 7c1cc5f0-2b71-462a-907e-191b0d3ee819
ports:
- name: http-metrics
port: 10255
protocol: TCP
- name: cadvisor
port: 4194
protocol: TCP
- name: https-metrics
port: 10250
protocol: TCP
kind: List
metadata:
resourceVersion: ""
selfLink: ""