Nginx exporter not found Ingress nginx

10/23/2019

I'm trying to post metrics from my nginx-ingress to prometheus. I've read kubernetes.io readme files for deployment and configuration. My nginx is running without fails, but node exporter is failing after a retry.

I have two containers in mentioned pod as a side cars, configured as below in my environment.

Why does nginx exporter keep failing?

My nginx-ingress.yaml file is shown below:

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 down below:

- 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
-- orhun.begendi
kubernetes
nginx
nginx-ingress
prometheus
prometheus-node-exporter

1 Answer

10/23/2019

You don't need to add an exporter to nginx-ingress, please read the documentation about the annotations you added.

Those annotations activate the exporter directly on the ingress exporter, with your configuration you open the port 9113 2 times, remove the prometheus exporter container and it should work.

-- night-gold
Source: StackOverflow