What is the correct way to map one custom-domain to many services?

steevee

The instructions for mapping-custom-domains with GKE with Cloud Run works fine for a 1:1 domain:service mapping. But what if I want to have, 1:M domain:services and match with the URI,

myapp.com/login  >> login-service
myapp.com/logout >> logout-service

What I've tried

The second domain-mapping creation statement will error as domain must be unique across services:

$ gcloud beta run domain-mappings create --service login-service --domain myapp.com     --cluster mycluster     --cluster-location europe-west2-a
Creating......done.                                                                                                                                         
RECORD TYPE  CONTENTS
A            XX.XXX.XXX.XX

$ gcloud beta run domain-mappings create --service login-service --domain myapp.com     --cluster mycluster     --cluster-location europe-west2-a
ERROR: ... "message": domainmappings.domains.cloudrun.com \"myapp.com\" already exists ...

Previously, when using a manually created Knative environment, I could achieve this with an Istio VirtualService:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: entry-route
  namespace: default
spec:
  - knative-ingress-gateway.knative-serving.svc.cluster.local
  # Set host to the domain name that you own.
  hosts:
  - myapp.com
  http:
  - match:
    - uri:
        prefix: "/login"
    rewrite:
      authority: login-service.default.myapp.com
    route:
      - destination:
          host: knative-ingressgateway.istio-system.svc.cluster.local
        weight: 100
  - match:
    - uri:
        prefix: "/logout"
    rewrite:
      authority: logout-service.default.myapp.com
    route:
      - destination:
          host: knative-ingressgateway.istio-system.svc.cluster.local
        weight: 100

But whilst I can apply this on GKE with Cloud Run, everything is routed to the service mapped to the domain.

I've also tried deleting the gcloud beta run domain-mappings created, setting the istio-ingressgateway LoadBalancer to a reserved static IP, and pointing my domain at the LoadBalancer. However, this just results in 503s.

Why can't I just point to the istio-ingressgateway LoadBalancer and let a VirtualService route for me?

steevee

It is possible to use a VirtualService to reroute traffic using the same domain and its path to multiple services.

istio-ingressgateway is now the default Knative service hostname (I was using an older Knative version and knative-ingressgateway has since been removed).

  1. Do not use gcloud beta run domain-mappings create .... It is not necessary for an M:1 service:domain mapping.
  2. Get the EXTERNAL-IP used by your istio-ingressgateway LoadBalancer (kubectl get svc istio-ingressgateway -n istio-system) and point your domain at it (e.g. myapp.com)
  3. Get the Knative service hostname with kubectl get svc (listed under EXTERNAL-IP - i.e. istio-ingressgateway.istio-system.svc.cluster.local)
  4. Apply a VirtualService that maps its route destinations to istio-ingressgateway.istio-system.svc.cluster.local:
# e.g. routing.yaml (`kubectl apply -f routing.yaml`)
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: entry-route
  namespace: default
spec:
  - knative-ingress-gateway.knative-serving.svc.cluster.local
  # Set host to the domain name that you own.
  hosts:
  - myapp.com
  http:
  - match:
    - uri:
        prefix: "/login"
    rewrite:
      authority: login-service.default.myapp.com
    route:
      - destination:
          host: istio-ingressgateway.istio-system.svc.cluster.local
        weight: 100
  - match:
    - uri:
        prefix: "/logout"
    rewrite:
      authority: logout-service.default.myapp.com
    route:
      - destination:
          host: istio-ingressgateway.istio-system.svc.cluster.local
        weight: 100

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What is the correct way to select one of many child elements in React?

What is the correct way to make a custom .NET Exception serializable?

What is the correct way to map textures onto SCNSphere

Minimal and correct way to map one-to-many with NHibernate

What is the correct way of managing transactionality in RxJava Services?

What is the correct way to sample a 16-bit height map in OpenGL

Flutter - what is correct way to invoke custom icon glyph?

What is the correct way to return map iterator from nested component?

What is the correct way to add a custom component to a reactive form's FormGroup?

what is correct way to define Many2Many, Many2One in mongoengine

what is the correct way to pass not services to the constructor of a custom normalize in symfony

What is correct way to declare UnmarshalJSON for custom type?

What is the correct way to do many to many entity relation insert?

What is the most easiest way to configure between AWS server and custom domain

What is the correct way to add a PCTC SSR in SITA Web Services (SWS)

What is the correct way of using a many-to-many relation with the same model

What is the correct way to send a custom event to Google Analytics and capture that data?

Best way to map one value to many

What is the correct way of implementing this custom priority_queue

What is the correct way to do a redirection from www. to the naked domain (Server or App or Domain Provider)?

Correct way to maintain a One to many relation with fixed count of children rows?

What is the best way to map a Many to Many relationship in mongoose

What's the correct way to schedule many tasks for an accurate duration later?

What is the correct way to parse the list items using Map?

MassTransit Saga: what is correct way to inject scoped services?

What is the recommended way to use domain-specific services as part of common services in angular?

Is there a way to present One2Many Relation in correct way in realm?

what is correct way of reference to value in object/map type value in terraform

What is the correct way to map and print unique dataset objects in React?