0

我正在尝试将我的 nginx-ingress 中的指标发布到普罗米修斯。我已经阅读了 kubernetes.io 自述文件以进行部署和配置。我的 nginx 运行没有失败,但重试后节点导出器失败。

我在提到的吊舱中有两个容器作为边车,在我的环境中配置如下。

为什么 nginx 导出器总是失败?

我的 nginx-ingress.yaml 文件如下所示:

spec:
  selector:
    matchLabels:
      app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9113"
    spec:
      serviceAccountName: nginx-ingress
      containers:
      - image: nginx/nginx-ingress:edge
        name: nginx-ingress
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: https
          containerPort: 443
          hostPort: 443
        - name: stub
          containerPort: 8080
          hostPort: 8080
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        args:
          - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
          - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
          - -enable-prometheus-metrics
         #- -v=3 # Enables extensive logging. Useful for trooublshooting.
         #- -report-ingress-status
         #- -external-service=nginx-ingress
         #- -enable-leader-election
      - image: nginx/nginx-prometheus-exporter:0.4.2
        name: nginx-prometheus-exporter
        ports:
        - name: prometheus
          containerPort: 9113
        args:
          - -web.listen-address
          - :9113
          - -nginx.scrape-uri=http://127.0.0.1:8080/stub_status
          - -nginx.retries=5
          - -nginx.retry-interval=1

Prometheus-cfg.yaml 如下:

- job_name: 'ingress-nginx-endpoints'
  kubernetes_sd_configs:
  - role: pod
    namespaces:
      names:
      - nginx-ingress
  relabel_configs:
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    action: keep
    regex: true
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scheme]
    action: replace
    target_label: __scheme__
    regex: (https?)
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
    action: replace
    target_label: __metrics_path__
    regex: (.+)
  - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
    action: replace
    target_label: __address__
    regex: ([^:]+)(?::\d+)?;(\d+)
    replacement: $1:$2
  - source_labels: [__meta_kubernetes_service_name]
    regex: prometheus-server
    action: drop
4

1 回答 1

1

您不需要向 nginx-ingress 添加导出器,请阅读有关您添加的注释的文档。

这些注释直接在入口导出器上激活导出器,使用您的配置打开端口 9113 2 次,删除 prometheus 导出器容器,它应该可以工作。

于 2019-10-23T08:06:08.480 回答