<p>I'm trying to set up an Ingress rule for a service (Kibana) running in my microk8s cluster but I'm having some problems.</p>
<p>The first rule set up is</p>
<pre><code>Name:             web-ingress
Namespace:        default
Address:          127.0.0.1
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
TLS:
  k8s-ingress-tls terminates web10
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /   web-service:8080 (10.1.72.26:8080,10.1.72.27:8080)
Annotations:  nginx.ingress.kubernetes.io/rewrite-target: /
              nginx.ingress.kubernetes.io/ssl-redirect: false
Events:       &lt;none&gt;
</code></pre>
<p>I'm trying to set Kibana service to get served on path /kibana</p>
<pre><code>Name:             kibana
Namespace:        default
Address:          127.0.0.1
Default backend:  default-http-backend:80 (&lt;error: endpoints &quot;default-http-backend&quot; not found&gt;)
TLS:
  k8s-ingress-tls terminates web10
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /kibana(/|$)(.*)   kibana:5601 (10.1.72.39:5601)
Annotations:  nginx.ingress.kubernetes.io/ssl-redirect: false
Events:
  Type    Reason  Age   From                      Message
  ----    ------  ----  ----                      -------
  Normal  CREATE  17m   nginx-ingress-controller  Ingress default/kibana
  Normal  UPDATE  17m   nginx-ingress-controller  Ingress default/kibana
</code></pre>
<p>My problem is that first thing Kibana does is returns a 302 redirect to host/login?next=%2F which gets resolved by the first Ingress rule because now I've lost my /kibana path.</p>
<p>I tried adding <code>nginx.ingress.kubernetes.io/rewrite-target: /kibana/$2</code> but redirect then just looks like <code>host/login?next=%2Fkibana%2F</code> which is not what I want at all.</p>
<p>If I delete the first rule, I just get 404 once Kibana does a redirect to host/login?next=%2F</p>

<p>Add the following annotation to the <code>kibana</code> ingress so that nginx-ingress interprets the <code>/kibana(/|$)(.*)</code> path using regex:</p>
<pre><code> nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
</code></pre>
<p>Additional detail:
To let kibana know that it runs on <code>/kibana</code> path, add the following env variable to the kibana pod/deployment:</p>
<pre><code>        - name: SERVER_BASEPATH
          value: /kibana
</code></pre>
