Bootstrap

Kubernetes Promethues监控集群外服务(Mysql示例)

安装mysqld_export

找一台服务器安装即可,按照 https://github.com/prometheus/mysqld_exporter 文档安装即可

Kubernetes配置

配置End-Pointer

apiVersion: v1
kind: Endpoints
metadata:
  labels:
    app: mysqld-exporter-metrics
  name: mysqld-exporter-metrics
  namespace: monitoring
  resourceVersion: "37417798"
  uid: 629a0ed2-9200-4129-97ed-a77014141714
subsets:
- addresses:
  - ip: #Mysqld_Exporter地址
  ports:
  - name: metrics
    port: 9104 #指标暴露的端口
    protocol: TCP


配置Service

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mysqld-exporter-metrics
  name: mysqld-exporter-metrics
  namespace: monitoring
spec:
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - name: metrics
    port: 9913
    protocol: TCP
    targetPort: 9913
  sessionAffinity: None
  type: ClusterIP

配置ServiceMonitor即可

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  generation: 1
  labels:
    app: mysqld-exporter-metrics
  name: mysqld-exporter-metrics
  namespace: monitoring
spec:
  endpoints:
  - honorLabels: true
    interval: 10s
    path: /metrics
    port: metrics
    scheme: http
    scrapeTimeout: 10s
  namespaceSelector:
    matchNames:
    - monitoring
  sampleLimit: 0
  selector:
    matchLabels:
      app: external-nginx

;