K8s: Multiple nginx-ingress-controller ingress rules in GKE

4/3/2019

I have a catch all ingress rule for a domain *.foo.com, and then I have one specific rule for a domain a.foo.com. According to the documentation, the ingress rule for a.foo.com must take priority over the one with a wildcard (because it's a better match than the wildcard). However, this isn't happening. How do I set priorities explicitly? What am I doing wrong?

Here's my generic ingress rule:

$ kubectl describe ing foo
Name:             foo
Namespace:        foo
Address:          x.x.x.x
Default backend:  default-http-backend:80 (x.x.x.x:8080)
TLS:
  foo.com terminates *.foo.com
Rules:
  Host             Path  Backends
  ----             ----  --------
  *.foo.com
                   /   foo:8888 (<none>)

Here's the domain specific rule:

$ kubectl describe ing foo-a
Name:             foo-a
Namespace:        foo
Address:          x.x.x.x
Default backend:  default-http-backend:80 (x.x.x.x:8080)
TLS:
  foo.com terminates a.foo.com
Rules:
  Host                                Path  Backends
  ----                                ----  --------
  a.foo.com
                                      /hello   foo-a:8080 (<none>)
-- judepereira
kubernetes
nginx
nginx-ingress

1 Answer

4/3/2019

You will need to configure each of your nginx-ingress controllers to have a different ingress-class name. Then in your ingress definition, you should specify the kubernetes.io/ingress.class: "my-ingress" to point to the ingress controller you want to use for that particular ingress.

Setup details are included in the [nginx-ingress docs].(https://kubernetes.github.io/ingress-nginx/user-guide/multiple-ingress/)

Hope this helps!

-- Frank Yucheng Gu
Source: StackOverflow