kubernetes multi domain dynamic routing

2/17/2020

Hello I would like to know how to dynamically route multiple domains to different services in Kubernetes, I'm trying to let my users add a domain to their accounts and based on that domain route to a specific service to render their webpage but with their domain. I have no idea where to start and would like to know if this is possible with Kubernetes.

-- nysertxs
google-cloud-platform
kubernetes
kubernetes-ingress
nginx-ingress

3 Answers

2/17/2020

You can create ingress object to route the traffic based on host URL.

 Ex:
 apiVersion: networking.k8s.io/v1beta1
 kind: Ingress
 metadata:
   name: name-virtual-host-ingress
 spec:
    rules:
    - host: foo.bar.com   
      http:
        paths:
        - backend:
            serviceName: service1
            servicePort: 80
    - host: bar.foo.com
      http:
        paths:
          - backend:
              serviceName: service2
              servicePort: 80
-- Subramanian Manickam
Source: StackOverflow

2/17/2020

Since you have tagged the question with google cloud my answer is geared towards google cloud.

For HTTP/HTTPS type traffic you can create an ingress resource and the ingress controller(nginx or GKE ingress) will create a HTTP Loadbalancer in google cloud. Then you can provision a static IP to the load balancer. Finally you can configure your domain in DNS to route traffic to that static IP whenever an user hits your domain.

Guide on how to create ingress and provision static IP.

Guide on configuring domain names with static IP.

Full guide on using nginx ingress controller in google cloud.

Here is the architecture of above nginx guide.

enter image description here

For multi domain use case you just extend the above and configure different domains using the same construct.

-- Arghya Sadhu
Source: StackOverflow

2/17/2020

assuming that all these services are HTTP(s) based 2 things need to happen:

  • an ingress object should be created that routes a given domain to an appropriate service (see https://kubernetes.io/docs/concepts/services-networking/ingress/)
  • proper records must be added to the DNS configuration of a given domain, (proabably a CNAME record pointing to your cluster, but it depends whether all traffic is supposed to be handled by your service or just a part of it)
-- morgwai
Source: StackOverflow