Trying to rewrite url for Grafana with Ingress

7/23/2019

In my kubernetes cluster I would like to do monitoring so I installed grafana.

I would like to access the grafana dashboard as http://example.com/monitoring, so I tried to include this in my ingress configuration

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: example.com
  http:
    paths:
    - path: /monitoring/(.*)
    backend:
     serviceName: grafana
     servicePort: 80

The idea is to add other paths there as well, for example / for the website.

I noticed that Grafana redirects http://example.com/monitoring to http://example.com/login. Of course this should have been http://example.com/monitoring/login. What would be the preferred way to fix this. Can it be done with ingress or should I somehow tell Grafana that it is behind a /monitoring path (if possible)?

I've installed grafana using this using Helm.

UPDATE: I've modified as suggested below the grafana chart's file values.yaml as follows

grafana.ini:
  server:
    domain: example.com
    root_url: http://example.com/monitoring/

Now I get:

enter image description here

And the heml command I use to install grafana:

gt; helm install stable/grafana -f values.yaml --
set persistence.enabled=true --set persistence.accessModes={ReadWriteOnce} --set persistence.size=8Gi -n grafana
-- Jeanluca Scaljeri
grafana
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

7/24/2019

This is a common problem with services that are behind an HTTP reverse-proxy. Luckily, Grafana offers a way to let it know the context path it is running behind.

In grafana.ini (which is most possibly supplied via a ConfigMap to its Kubernetes deployment), you need to specify the variables like the following:

[server]
domain = example.com
root_url = http://example.com/monitoring/

See the full documentation here: https://grafana.com/docs/installation/behind_proxy/

-- Utku Ă–zdemir
Source: StackOverflow