kube-prometheus ServiceMonitor使用
本文最后更新于 482 天前,其中的信息可能已经有所发展或是发生改变。

kube-prometheus ServiceMonitor使用

原理其实就是创建一个新的serviceMonitor后,prometheus会创建一个target

例子:ServiceMonitor.yaml

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
     k8s-app: xxx-exporter
  name: xxx
  namespace: prometheus 
spec:
  endpoints:
  - interval: 15s
    port:  xxx-exporter
  jobLabel:  xxx-exporter-monitor 
  namespaceSelector:
    matchNames:
    - monitor                #目标服务的namespaces
  selector:
    matchLabels:
      k8s-app: xx-exporter  # 目标服务的labels
namespaceSelector:
    any: true 

表示选择所有的namespace

上面ServiceMonitor是针对k8s集群内部服务监控,想监控集群外部的exporter通Endpoints实现

为外部 exporter 服务设置 service:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: monitoring-external-node-exporter
    app.kubernetes.io/name: node-exporter
    release: monitoring
  name: monitoring-external-node-exporter
  namespace: monitoring
spec:
  type: ClusterIP
  ports:
    - name: http-metrics
      port: 39xxx
      protocol: TCP
      targetPort: 39xxx

---
apiVersion: v1
kind: Endpoints
metadata:
  name: monitoring-external-node-exporter
  labels:
    app: monitoring-external-node-exporter
    app.kubernetes.io/name: node-exporter
    release: monitoring
  namespace: monitoring
subsets:
  - addresses:
      - ip: xx.xx.xx.xx
      - ip: xx.xx.xx.xx
    ports:
      - name: http-metrics
        port: 39xxx
        protocol: TCP
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: monitoring-external-node-exporter
    release: monitoring
  name: monitoring-external-node-exporter-sm
  namespace: monitoring
spec:
  endpoints:
    - interval: 30s
      port: http-metrics
      path: /metrics
      authorization:
      basicAuth:
        username:
          name: external-node-exporter-basic-auth
          key: user
        password:
          name: external-node-exporter-basic-auth
          key: password
  jobLabel: node-exporter
  namespaceSelector:
    matchNames:
      - monitoring
  selector:
    matchLabels:
      app: monitoring-external-node-exporter
      release: monitoring
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇