1

I'm trying to set up an Ingress rule for a service (Kibana) running in my microk8s cluster but I'm having some problems.

The first rule set up is

Name:             web-ingress
Namespace:        default
Address:          127.0.0.1
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
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:       <none>

I'm trying to set Kibana service to get served on path /kibana

Name:             kibana
Namespace:        default
Address:          127.0.0.1
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
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

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.

I tried adding nginx.ingress.kubernetes.io/rewrite-target: /kibana/$2 but redirect then just looks like host/login?next=%2Fkibana%2F which is not what I want at all.

If I delete the first rule, I just get 404 once Kibana does a redirect to host/login?next=%2F

lovrodoe
  • 473
  • 8
  • 18

1 Answers1

2

Add the following annotation to the kibana ingress so that nginx-ingress interprets the /kibana(/|$)(.*) path using regex:

 nginx.ingress.kubernetes.io/use-regex: "true"

Additional detail: To let kibana know that it runs on /kibana path, add the following env variable to the kibana pod/deployment:

        - name: SERVER_BASEPATH
          value: /kibana
Lukman
  • 18,462
  • 6
  • 56
  • 66
  • It does interpret it using regex, do I need to rewrite the path? Kibana on it's own is not on host:port/kibana, it's on host:port. The problem I'm having is that it gets redirected to host/login?next=%2F and I lose the /kibana part so it gets resolved by the first Ingress rule. Hopefully I explained it well and I will add it to the main post. – lovrodoe May 17 '21 at 14:19
  • @lovrodoe, no need for the rewrite, you just need to tell kibana that it runs on `/kibana` path by adding the env var I've added to my answer (the env var is specific to kibana only, other app might require different env var or setting). – Lukman May 17 '21 at 14:28
  • Rewrite was necessary after all due [this](https://stackoverflow.com/questions/46181930/nginx-infinte-redirection-for-kibana-on-centos-7) problem with Kibana when server basepath is changed. Setting I used was `nginx.ingress.kubernetes.io/rewrite-target: /$2 break;` in my .yml and everything now works as expected. Thanks, Lukman. – lovrodoe May 17 '21 at 14:48