K8s ingress responding to multiple server names without having them configured?

1/28/2021

I'm pretty new to K8s in general and I'm a developer not exactly a network guy so I would like some ideas on how to reach my goal so I could research a bit on it.

Let's say I have my app (hosted on k8s), let's say myapp.domain.com. Let's imagine I have a new customer, they want their own URL... let's say backoffice.company.com. For this to work I would have to go into my k8's ingress and add "backoffice.company.com" to the hosts. Now let's imagine I have... 30000 customers doing this........... okay u get the point.

One idea that came to my mind was to use an external nginx for example which listens to all servernames and just proxies them to "myapp.domain.com". But this forces me to have an extra server just to serve as proxy :/

Is there a way, maybe via TXT records or something like that to make the ingress verify that the request is to 'myapp'?

Thanks

-- Joaogl
dns
kubernetes
kubernetes-ingress
networking
nginx

1 Answer

1/28/2021

You may expose service directly to clients using Load Balancer and add wildcard dns CNAME record *.company.com pointing to Load Balancer. In that case you don't need Nginx Ingress which reduces latency for your clients and removes one possible bottleneck.

If you still want Nginx Ingress then you may use hostname wildcards like this:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-wildcard-host
spec:
  rules:
  - host: "*.foo.com"
    http:
      paths:
      - pathType: Prefix
        path: "/foo"
        backend:
          service:
            name: service2
            port:
              number: 80
-- Vasili Angapov
Source: StackOverflow