I&B Monitoring Platform documentation

Nginx-ingress metrics

To enable metrics expose from nginx-ingress controller you need to install in kubernetes with helm and set value

helm install ingress-nginx ingress-nginx/ingress-nginx \
  --set controller.metrics.enabled=true \
  --set <your values>

after this deploy your ingress expose metrics in kubernetes on http://ingress-nginx-ingress-nginx-controller-metrics.ingress-nginx.svc.cluster.local:10254/metrics

For access with basic auth and encryption from outside the kubernetes you need to deploy kubernetes ingress object with basic autentification and tls encryption. For this do.

  1. Create a Secret for Basic Authentication

First, generate a .htpasswd file containing the username and a hashed password. For example, to create a user named prometheus with a password, use the htpasswd utility:

htpasswd -c auth prometheus

This command will prompt for a password and create a file named auth in the current directory. Next, create a Kubernetes Secret from this file:

kubectl create secret generic basic-auth --from-file=auth

This creates a Secret named basic-auth in your current namespace, containing the auth file as a key in its data.

  1. Create self signed certificate as its created in section Authentication

  2. Create kubernetes secret from this certificate

kubectl create secret tls ingress-local-tls \
  --cert=exporter.crt \
  --key=exporter.key

Create the yaml file of ingress with tls and basic auth

nano ingress-metrics.yaml

and paste into opened file

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-metrics
  annotations:
    nginx.ingress.kubernetes.io/auth-type: basic  #basic auth annotation
    nginx.ingress.kubernetes.io/auth-secret: basic-auth   #basic auth annotation
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - user'   #basic auth annotation
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - ingress-metrics.com
      secretName: ingress-local-tls
  rules:
  - host: ingress-metrics.com
    http:
      paths:
      - path: /metrics
        pathType: Prefix
        backend:
          service:
            name: ingress-nginx-ingress-nginx-controller-metrics
            port:
              number: 10254

Save and exit from file. And create ingress object. For this run

kubectl apply -f ingress-metrics.yaml

After deploy ingress, metrics of your ingress controller will exposed on url: https://ingress-metrics.com/metrics

after login to this URL you will see some like this:

image-20251003-073800.png

Enjoy!)