Prometheus Operator 监控 Traefik V2.4

背景:

traefik搭建方式如下:
https://www.yuque.com/duiniwukenaihe/ehb02i/odflm7 。
Prometheus-oprator搭建方式如下:
https://www.yuque.com/duiniwukenaihe/ehb02i/tm6vl7。
Prometheus的文档写了grafana添加了traefik的监控模板。但是现在仔细一看。traefik的监控图是空的,Prometheus的 target也没有对应traefik的监控。
现在配置下添加traefik服务发现以及验证一下grafana的图表。

1. Prometheus Operator 监控 Traefik V2.4

1.1. Traefik 配置文件设置 Prometheus

参照https://www.yuque.com/duiniwukenaihe/ehb02i/odflm7。配置中默认开启了默认的Prometheus监控。
Prometheus Operator 监控 Traefik V2.4
https://doc.traefik.io/traefik/observability/metrics/prometheus/可参照traefik官方文档。

1.2、Traefik Service 设置标签

1.2.1 查看traefik service

$  kubectl get svc -n kube-system
NAME                          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE
cilium-agent                  ClusterIP   None9095/TCP                       15d
etcd-k8s                      ClusterIP   None2379/TCP                       8d
hubble-metrics                ClusterIP   None9091/TCP                       15d
hubble-relay                  ClusterIP   172.254.38.5080/TCP                         15d
hubble-ui                     ClusterIP   172.254.11.23980/TCP                         15d
kube-controller-manager       ClusterIP   None10257/TCP                      8d
kube-controller-manager-svc   ClusterIP   None10252/TCP                      6d
kube-dns                      ClusterIP   172.254.0.1053/UDP,53/TCP,9153/TCP         15d
kube-scheduler                ClusterIP   None10259/TCP                      8d
kube-scheduler-svc            ClusterIP   None10251/TCP                      6d
kubelet                       ClusterIP   None10250/TCP,10255/TCP,4194/TCP   8d
traefik                       ClusterIP   172.254.12.8880/TCP,443/TCP,8080/TCP        11d

1.2.2、编辑该 Service 设置 Label

 kubectl edit service traefik -n kube-system

设置 Label “app: traefik”
Prometheus Operator 监控 Traefik V2.4
参照的是traefik-deploy.yaml 中的app:traefik这个标签用了,当然了也可以自己定义下用下别的…
Prometheus Operator 监控 Traefik V2.4

1.3、Prometheus Operator 配置监控规则

traefik-service-monitoring.yaml

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name:  traefik
  namespace: monitoring
  labels:
     app: traefik
spec:
  jobLabel: traefik-metrics
  selector:
    matchLabels:
      app: traefik
  namespaceSelector:
    matchNames:
    - kube-system
  endpoints:
  - port: admin
    path: /metrics

创建该Service Monitor

$ kubectl apply -f traefik-monitor.yaml

1.4、查看 Prometheus target规则是否生效

Prometheus Operator 监控 Traefik V2.4

1.5 查看grafana中的traefik仪表盘是否有数据生成图表

Prometheus Operator 监控 Traefik V2.4
嗯 这也算是添加target的一个例子。下次写下配置下自动发现规则?

上一篇:DataSet、DataTable、DataView三者关系及DataView 常见用法


下一篇:使用traefik作为istio流量入口,并在traefik上实现流量控制