1

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:

$> helm install stable/grafana -f values.yaml --set persistence.enabled=true --set persistence.accessModes={ReadWriteOnce} --set persistence.size=8Gi -n grafana
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333

1 Answers1

4

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
  • 7,390
  • 2
  • 52
  • 49
  • You're right, but I've installed Grafana with Helm (checkout my updated question). I've updated the values.yaml, but no luck – Jeanluca Scaljeri Jul 25 '19 at 15:36
  • @JeanlucaScaljeri Just a guess: can you try to remove the rewrite in the ingress, only keep the path as `/monitoring/` and try again? It might be that the `root_url` instruction in Grafana causes it itself to be served from `/monitoring` context path. – Utku Özdemir Jul 25 '19 at 18:59
  • 1
    It turned out to be an Ingress rewrite issue. So it works like a charm now. Thanks a lot for the help! – Jeanluca Scaljeri Jul 25 '19 at 20:25
  • Ran into same error as in this question, though I have following entries in kube-prometheus-stack/charts/grafana/values.yaml. Any clue what else to check? grafana.ini: ... server: domain: sandboxgr.myorg.com root_url: https://sandboxgr.myorg.com/ – cnu Oct 13 '20 at 21:32
  • this solution worked for me. Took while to figure the grafana helm values yaml. The comment not showing my indents. :( `grafana: enabled: true grafana.ini: server: domain: a9####3f1.elb.us-east-1.amazonaws.com root_url: http://a956####f1.elb.us-east-1.amazonaws.com/grafana/ serve_from_sub_path: true` this was behind network load balancer in aws. – Michael Sampson Jul 06 '21 at 13:04