Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

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

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

question from:https://stackoverflow.com/questions/65936477/k8s-ingress-responding-to-multiple-server-names-without-having-them-configured

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...