Multiple Ingresses with multiple paths - how are the paths regexes prioritized?

7/16/2019

When running multiple ingress controllers under Kubernetes with the same host, how are the Regexes evaluated? Does the order matter?

Basically, I have one ingress for the API and another for the frontend.

The API being on example.com/api/ -> api/(.*)

The frontend being on example.com -> (.*)

Does the order I deploy these matter? Since the regex for the frontend will essentially just be (.*), if this is evaluated before the /api/(.*) regex, all traffic will be sent to the frontend, which I don't want.

How can I avoid this?

Thanks, James

-- James B.
kubernetes-ingress
nginx-ingress

1 Answer

7/16/2019

Regular expressions follow a first match policy.

Ingress-nginx orders the paths by descending length before putting them into the config.

So in your case it will match api/(.*) on the first place

Also, do not forget that you have to enable regexes with following annotation

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