<p>I have install the Grafan in my Kubenernetes 1.9 cluster. When I access with my ingress URL  (<a href="http://sample.com/grafana/" rel="noreferrer">http://sample.com/grafana/</a> ) getting the first page. After that javascript, css download not adding /grafana to the URL.</p>

<p>here is my ingress rule:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: grafana-ingress-v1
  namespace: monitoring
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
spec:
  tls:
  - hosts:
    - sample.com
    secretName: ngerss-tls
  rules:
  - host: sample.com
    http:
      paths:
      - path: /grafana/
        backend:
          serviceName: grafana-grafana
          servicePort: 80
</code></pre>

<p>Here I see the discussion about the same topic. but its not helping my issue.</p>

<p><a href="https://github.com/kubernetes/contrib/issues/860" rel="noreferrer">https://github.com/kubernetes/contrib/issues/860</a>
Below images shows first request goes to /grafana/ but second request didn't get added <code>/grafana/</code> in the url.</p>

<p><a href="https://i.stack.imgur.com/UL2Xh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UL2Xh.png" alt="enter image description here"></a></p>

<p>Your ingress rule is correct and nginx creates correct virtual host to forward traffic to grafana's service (I left only needed strings to show):</p>

<pre><code> server {
    server_name sample.com;
    listen 80;
    listen [::]:80;
    set $proxy_upstream_name "-";

    location ~* ^/grafana/(?&lt;baseuri&gt;.*) {

        set $proxy_upstream_name "default-grafana-grafana-80";

        set $namespace      "default";
        set $ingress_name   "grafana-ingress-v1";


    rewrite /grafana/(.*) /$1 break;
    rewrite /grafana/ / break;
    proxy_pass http://default-grafana-grafana-80;

    }
</code></pre>

<p>And yes, when you go to <code>sample.com/grafana/</code> you get the response from grafana pod, but it redirects to <code>sample.com/login</code> page (you see this from screenshot you provided):</p>

<pre><code>$ curl -v -L http://sample.com/grafana/
*   Trying 192.168.99.100...
* Connected to sample.com (192.168.99.100) port 80 (#0)
&gt; GET /grafana/ HTTP/1.1
&gt; Host: sample.com
&gt; User-Agent: curl/7.47.0
&gt; Accept: */*
&gt; 
&lt; HTTP/1.1 302 Found
&lt; Server: nginx/1.13.5
&lt; Date: Tue, 30 Jan 2018 21:55:21 GMT
&lt; Content-Type: text/html; charset=utf-8
&lt; Content-Length: 29
&lt; Connection: keep-alive
&lt; Location: /login
&lt; Set-Cookie: grafana_sess=c07ab2399d82fef4; Path=/; HttpOnly
&lt; Set-Cookie: redirect_to=%252F; Path=/
&lt; 
* Ignoring the response-body
* Connection #0 to host sample.com left intact
* Issue another request to this URL: 'http://sample.com/login'
* Found bundle for host sample.com: 0x563ff9bf7f20 [can pipeline]
* Re-using existing connection! (#0) with host sample.com
* Connected to sample.com (192.168.99.100) port 80 (#0)
&gt; GET /login HTTP/1.1
&gt; Host: sample.com
&gt; User-Agent: curl/7.47.0
&gt; Accept: */*
&gt; 
&lt; HTTP/1.1 404 Not Found
&lt; Server: nginx/1.13.5
&lt; Date: Tue, 30 Jan 2018 21:55:21 GMT
&lt; Content-Type: text/plain; charset=utf-8
&lt; Content-Length: 21
&lt; Connection: keep-alive
&lt; 
* Connection #0 to host sample.com left intact
default backend 404
</code></pre>

<p>because by default grafana's <code>root_url</code> is just <code>/</code>:</p>

<pre><code>root_url = %(protocol)s://%(domain)s:%(http_port)s/
</code></pre>

<p>and when request redirects to just <code>sample.com</code> nginx forwards it to default backend 404.</p>

<p><strong>Solution:</strong></p>

<p>You need to change <code>root_url</code> grafana's server setting to <code>/grafana/</code>:</p>

<pre><code>root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
</code></pre>

<p>You can do this changing this setting in grafana's <code>configmap</code> object.</p>
