2

我在 GKE 上的另一个端口(11100)上运行节点导出器,并将 prometheus.yml 配置为使用 kubernetes_sd_configs。但是,服务发现似乎正在返回带有Kubelet端口 (10250)的节点 IP <node-ip>:10250/metrics。我似乎找不到指定使用哪个端口的方法。有任何想法吗?

 - job_name: gke-nodes
      kubernetes_sd_configs:
      - role: node

此外, node-exporter 在 port 中正常运行11100。我通过在内部节点 IP 中执行 curl 来验证它,<node-ip>:11100/metrics它就像一个魅力


这是我的节点导出器定义

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter-ds
  namespace: monitoring
  labels:
    app: node-exporter
    belongsTo: monitoring
spec:
  selector:
    matchLabels:
      app: node-exporter
  template:
    metadata:
      labels:
        app: node-exporter
    spec:
      serviceAccountName: monitoring-sa
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: sys
          hostPath:
            path: /sys
      containers:
        - name: node-exporter
          image: prom/node-exporter:v0.18.1
          args:
            - "--web.listen-address=0.0.0.0:11100"
            - "--path.procfs=/proc_host"
            - "--path.sysfs=/host_sys"
          ports:
            - containerPort: 11100
              hostPort: 11100
          volumeMounts:
          - name: sys
            readOnly: true
            mountPath: /host_sys
          - name: proc
            readOnly: true
            mountPath: /proc_host
          imagePullPolicy: IfNotPresent
      hostNetwork: true
      hostPID: true
4

1 回答 1

4

以防万一有人遇到同样的问题,此配置将添加 k8s 节点 IP,其端口与Kubelet不同:

  - job_name: 'gke-nodes'
    kubernetes_sd_configs: 
    - role: node
    relabel_configs:
      - source_labels: [__address__]
        action: replace
        regex: ([^:]+):.*
        replacement: $1:11100 # port you want to use
        target_label: __address__

kubernetes_sd_config的默认行为是将具有Kubelet端口的节点的 IP 添加为目标,这在文档中指定:

节点角色为每个集群节点发现一个目标,其地址默认Kubelet 的 HTTP 端口

但是,您可以使用relabel_config覆盖__address__标签并将Kubelet端口替换为任何需要的端口。

于 2021-04-14T23:38:47.610 回答