wtysos11 / blogWiki

Use to store public paper and organize them.
17 stars 4 forks source link

prometheus-operator是如何监控的 #232

Open wtysos11 opened 3 years ago

wtysos11 commented 3 years ago

以prometheus-operator的ServiceMonitor为例子

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: prometheus
  name: prometheus
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s
    port: web
  selector:
    matchLabels:
      prometheus: k8s

在过去的时候,prometheus是通过annotation来进行监控,详情见k8s prometheus。(这个会更全一些) 但是在ServiceMonitor中,作用的单位从服务改为了endpoint,api文档中的这个endpoint并不是所谓意义的终端,而是字面意思上的k8s endpoint。

以上面的这个配置信息为例子,它会匹配endpoint中port名为web的端口,service label带有prometheus: k8s

endpoint中的名字也是由service指定的

apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    endpoints.kubernetes.io/last-change-trigger-time: "2021-07-30T14:23:20+08:00"
  creationTimestamp: "2021-07-29T09:25:54Z"
  labels:
    k8s-app: prometheusloadtestsvr
    kubernetes.io/cluster-service: "true"
    logic-monitor: "true"
  name: prometheusloadtestsvr
  namespace: monitoring
  resourceVersion: "8090354178"
  selfLink: /api/v1/namespaces/monitoring/endpoints/prometheusloadtestsvr
  uid: xxxxxx
subsets:
- addresses:
  - ip: xxxxxx
    nodeName: xxxxxx
    targetRef:
      kind: Pod
      name: prometheusloadtestsvr-767c5dd9d-2v7fj
      namespace: monitoring
      resourceVersion: "8090354176"
      uid: xxxxxx
  ports:
  - name: http
    port: 8080
    protocol: TCP