使用Prometheus Operator监控ubuntu服务器

时间:2018-09-20 22:27:00

标签: kubernetes monitoring prometheus prometheus-operator

我需要使用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

2 个答案:

答案 0 :(得分: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中。 enter image description here

答案 1 :(得分:0)

这是为我工作的完整解决方案。 记下我必须将Service type更改为ClusterIP的事实。

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下显示为端点。