Ingress routing rules to access prometheus server

4/9/2020

I have deployed prometheus server(2.13.1) on kubernetes(1.17.3), I am able to access it on http://my.prom.com:9090

But i want to access it on http://my.prom.com:9090/prometheus so i added following ingress rules but its not working

First Try:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /prometheus
  name: approot
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /

This results in 404 error

Second Try:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /prometheus(/|$)(.*)

Now when i access URL http://my.prom.com:9090/prometheus in browser it get changed to http://my.prom.com:9090/graph and show 404 error

-- ImranRazaKhan
kubernetes
kubernetes-ingress
prometheus

1 Answer

4/9/2020

Prometheus is not aware of what you are trying to achieve and that's why it's redirecting to unknown destination.

You have to tell prometheus to accept traffic on the new path as can be seen here and here.

Highlight to the second link, you have to include - "--web.route-prefix=/" and - "--web.external-url=http://my.prom.com:9090/prometheus" in your prometheus deployment.

Then I had to modify the prometheus deployment to accept traffic on the new path (/prom). This was covered in the Securing Prometheus API and UI Endpoints Using Basic Auth documentation:

In your env it should look like this:

> grep web deploy.yaml 
            - "--web.enable-lifecycle"
            - "--web.route-prefix=/"
            - "--web.external-url=http://my.prom.com:9090/prometheus"
-- mWatney
Source: StackOverflow