Can someone please explain to me when I would use the "App Root" annotation in Kubernetes

5/28/2019

I've read the docs a thousand times but I still don't understand how I would use the nginx.ingress.kubernetes.io/app-root annotation.

Can someone please provide an example + description in plain english?

Docs: https://kubernetes.github.io/ingress-nginx/examples/rewrite/

I might as well copy paste the entire text; it's not that much.

nginx.ingress.kubernetes.io/app-root    Defines the Application Root that the Controller must redirect if it's in '/' context   string

App Root

Create an Ingress rule with a app-root annotation:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /app1
  name: approot
  namespace: default
spec:
  rules:
  - host: approot.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /

Check the rewrite is working

$ curl -I -k http://approot.bar.com/
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.11.10
Date: Mon, 13 Mar 2017 14:57:15 GMT
Content-Type: text/html
Content-Length: 162
Location: http://stickyingress.example.com/app1
Connection: keep-alive
-- PussInBoots
kubernetes
nginx
nginx-ingress

1 Answer

7/15/2019

It simply redirects requests coming to '/' to a different path internally. This is useful if your application's root path is different from '/'.

For example, say your application is listening in '/server', you'd set your Nginx annotiations like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    annotations:
        nginx.ingress.kubernetes.io/app-root: /server

At this point, any incoming requests at example.com/ would be rewritten internally to go example.com/server, allowing your application to listen to them without having to explicitly specify incoming '/' requests.

-- yyyyahir
Source: StackOverflow