Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ingress controller multiple hosts

Tags:

kubernetes

Can I add multiple hosts to the Ingress controller so that they refer to the same target group in the aws load balancer? Example:

  rules:
  - host: ["foobar.com", "api.foobar.com",  "status.foobar.com"]
    http:
      paths:
      - backend:
          serviceName: foobar
          servicePort: 80 ```

like image 951
Bell Avatar asked Aug 01 '26 04:08

Bell


2 Answers

TLDR; no


Long answer:

In k8s source code you can see that host field's data type is string, so you cannot use array of strings in that place.

But you should be able to do the following:

rules:
- host: "foobar.com"
  http:
    paths:
    - backend:
        serviceName: foobar
        servicePort: 80
- host: "api.foobar.com"
  http:
    paths:
    - backend:
        serviceName: foobar
        servicePort: 80
- host: "status.foobar.com"
  http:
    paths:
    - backend:
        serviceName: foobar
        servicePort: 80
like image 101
Matt Avatar answered Aug 02 '26 19:08

Matt


You can use hostname wildcards if you are using Kubernetes > 1.18 version.

For more information check these links:

https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/basic-configuration/ https://kubernetes.io/docs/concepts/services-networking/ingress/

rules:
- host: "foobar.com"
  http:
    paths:
    - backend:
        serviceName: foobar
        servicePort: 80
- host: "*.foobar.com"
  http:
    paths:
    - backend:
        serviceName: foobar
        servicePort: 80
like image 27
Muneer Avatar answered Aug 02 '26 18:08

Muneer



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!