1
votes

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
2

2 Answers

4
votes

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/

1
votes

Update your grafana.ini config like this: The grafana.ini can mostly be found under grafana config map

kubectl get cm

kubectl edit cm map_name

data:
  grafana.ini: |
    [server]
    serve_from_sub_path = true
    domain = ingress-gateway.yourdomain.com
    root_url = http://ingress-gateway.yourdomain.com/grafana/

This grafana.ini is mostly saved under the config map or YAML files which can be edited. reapply or edit the rules & create a mapping in the ingress, that should work.