How does the nginx ingress process the routing rules?

1/25/2021

I have the following rules defined in the nginx ingress rules yml:

- host: my-domain.com
    http:
      paths:
        - path: /api
          backend:
            serviceName: api-service
            servicePort: 8080
        - path: /demo
          backend:
            serviceName: demo-service
            servicePort: 4096
        - path: /
          backend:
            serviceName: ui
            servicePort: 80

I have 3 services running. What I want is that the traffic going to my-domain/demo should be redirected to the demo-service, same for /api with the api-service service, and everything else should go to the ui service. However, this sample above does not work, my-domain.com/demo goes to 404. I do not use the rewrite annotation.

Any idea what is wrong with the routing?

-- Gábor Varga
kubernetes
kubernetes-ingress
nginx
nginx-ingress
routes

1 Answer

1/25/2021

@GáborVarga you need to check few things. 1. Check the output of command "kubectl get ingress", if you can see the resources. 2. What annotations you are using currently. Below is the list of few example annotations which can be used.

nginx.ingress.kubernetes.io/secure-backends: "false"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/session-cookie-path: "/"

These annotations are really important

nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/session-cookie-path: "/"
-- Nish
Source: StackOverflow