Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple ingress rules using same host

I have two ingress rules (for public/internal traffic), what I would like is for all endpoints to use the public ingress except for /metrics, which should be internal, all using the same host.

E.g.

example.com/ -> public ingress
example.com/metrics -> internal ingress

This is what I have tried:

internal ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-metrics-ingress
  annotations:
    kubernetes.io/ingress.class: ingress-internal
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /metrics
        backend:
          serviceName: example-servicename
          servicePort: 80

and public ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path:
        backend:
          serviceName: example-servicename
          servicePort: 80

The internal ingress is currently being ignored when I visit example.com/metrics (it uses the public one instead).

If I change the internal ingress to use the same ingress controller as the public one and change the service port to 81 (as an example), this provides an error (which is expected), this shows that the two different ingresses are being used. However, as soon as I use two different ingress controllers, then the one ingress' rules are not being picked up.

How can I configure my ingresses to achieve my desired result?

like image 622
xbfh0516 Avatar asked Aug 09 '26 16:08

xbfh0516


1 Answers

When running multiple ingress-nginx controllers, it will only process an unset class annotation if one of the controllers uses the default --ingress-class value (see IsValid method in internal/ingress/annotations/class/main.go), otherwise the class annotation become required.

If --ingress-class is set to the default value of nginx, the controller will monitor Ingresses with no class annotation and Ingresses with annotation class set to nginx. Use a non-default value for --ingress-class, to ensure that the controller only satisfied the specific class of Ingresses.

In your case use the combination of the annotation kubernetes.io/ingress.class: "EXTERNAL|INTERNAL" and the flag --ingress-class=EXTERNAL|INTERNAL allows you to filter which Ingress rules should be picked by the nginx ingress controller.

Take a look: multiple-ingress, ingress-nginx-traffic.

like image 114
Malgorzata Avatar answered Aug 13 '26 13:08

Malgorzata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!