'Unable to get a Grafana helm-charts URL to work with subpath

I am setting up a Grafana server on my local kube cluster using helm-charts. I am trying to get it to work on a subpath in order to implement it on a production env with tls later on, but I am unable to access Grafana on http://localhost:3000/grafana.

I have tried all most all the recommendations out there on the internet about adding a subpath to ingress, but nothing seems to work.

The Grafana login screen shows up on http://localhost:3000/ when I remove root_url: http://localhost:3000/grafana from Values.yaml

But when I add root_url: http://localhost:3000/grafana back into values.yaml file I see the error attached below (towards the end of this post).

root_url: http://localhost:3000/grafana and ingress as:
ingress:
  enabled: true
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /

  labels: {}
  path: /grafana
  hosts:
    - localhost
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: {}

I expect the http://localhost:3000/grafana url to show me the login screen instead i see the below errors:

If you're seeing this Grafana has failed to load its application files 

1. This could be caused by your reverse proxy settings.

2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath

3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build

4. Sometimes restarting grafana-server can help

Can you please help me fix the ingress and root_url on values.yaml to get Grafana URL working at /grafana ?



Solution 1:[1]

As you check documentation for Configuring grafana behind Proxy, root_url should be configured in grafana.ini file under [server] section. You can modify your values.yaml to achieve this.

grafana.ini:
  ...
  server:
    root_url: http://localhost:3000/grafana/

Also your ingress in values should look like this.

ingress:
  enabled: true
  annotations: 
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  labels: {}
  path: /grafana/
  hosts:
    - ""

Hope it helps.

Solution 2:[2]

I followed exact steps mentioned by @coolinuxoid however, I still faced issue when trying to access UI by hitting http://localhost:3000/grafana/

I got redirected to http://localhost:3000/grafana/login with no UI displayed.

A small modification helped me achieve accessing UI through http://localhost:3000/grafana/

In the grafana.ini configuration, I added "serve_from_sub_path: true", so my final grafana.ini looked something like this:

grafana.ini:
server:
  root_url: http://localhost:3000/grafana/
  serve_from_sub_path: true

Ingress Configuration were exactly same. If it is version specific issue, I cannot be sure but I'm using Grafana v8.2.1.

Solution 3:[3]

You need to tell the grafana application, that it is run not under the root url / (the default), but under some subpath. The easiest way is via GF_ prefixed env vars:

grafana:
  env:
    GF_SERVER_ROOT_URL: https://myhostname.example.com/grafana
    GF_SERVER_SERVE_FROM_SUB_PATH: 'true'
  ingress:
    enabled: true
    hosts:
    - myhostname.example.com
    path: /grafana($|(/.*))
    pathType: ImplementationSpecific

Above example works for the kubernetes' nginx-ingress-controller. Depending on the ingress controller you use, you may need

    path: /grafana
    pathType: Prefix

instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 coolinuxoid
Solution 2 Rahul Kawadkar
Solution 3 geekQ