1

我需要使用 Prometheus Operator 监控多个 ubuntu 服务器。这些服务器位于运行我的 prometheus 操作员的 kubernetes 集群之外。下面的清单用于监控其中一台具有 IP 的服务器aaa.bbb.ccc.ddd。如何添加多个 IP 作为端点进行监控?或者我是否需要为每台服务器创建一个端点/服务?

apiVersion: v1
kind: Service
metadata:
  name: external-server
  namespace: monitoring
  labels:
    k8s-app: external-server
spec:
  type: ExternalName
  externalName: aaa.bbb.ccc.ddd
  clusterIP: ""
  ports:
  - name: metrics
    port: 9100
    protocol: TCP
    targetPort: 9100

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: external-server
  labels:
    k8s-app: external-server
spec:
  endpoints:
  - port: metrics
    interval: 30s
    honorLabels: true
    path: /metrics
  selector:
    matchLabels:
      k8s-app: external-server
  namespaceSelector:
    matchNames:
    - monitoring

apiVersion: v1
kind: Endpoints
metadata:
  name: external-server
  labels:
    k8s-app: external-server
subsets:
- addresses:
  - ip: aaa.bbb.ccc.ddd
  ports:
  - name: metrics
    port: 9100
    protocol: TCP
4

2 回答 2

0

只需使用

apiVersion: v1
kind: Endpoints
metadata:
  name: external-server
subsets:
- addresses:
  - ip: aaa.bbb.ccc.ddd
  - ip: aaa.bbb.ccc.eee
  - ip: aaa.bbb.ccc.fff
  ports:
  - name: metrics
    port: 9100
    protocol: TCP

一个带有多个端点的新目标将被添加到 Prometheus /targets在此处输入图像描述

于 2018-09-21T16:30:47.287 回答
0

这是对我有用的完整解决方案。请注意我必须将 更改Service typeClusterIP.

apiVersion: v1
kind: Service
metadata:
  name: external-server
  namespace: monitoring
  labels:
    k8s-app: external-server
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - name: metrics
    port: 9100
    protocol: TCP

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: external-server
  labels:
    k8s-app: external-server
spec:
  endpoints:
  - port: metrics
    interval: 30s
    scheme: http
  selector:
    matchLabels:
      k8s-app: external-server
  namespaceSelector:
    matchNames:
    - monitoring

apiVersion: v1
kind: Endpoints
metadata:
  name: external-server
  labels:
    k8s-app: external-server
subsets:
- addresses:
  - ip: aaa.bbb.ccc.ddd
  - ip: aaa.bbb.ccc.eee
  ports:
  - name: metrics
    port: 9100
    protocol: TCP

部署后,这两个 IP 将显示为 下的Targets端点external-server

于 2018-09-21T22:13:13.910 回答