3
votes

I want to setup web app using three components that i already have:

  1. Domain name registered on domains.google.com
  2. Frontend web app hosted on Firebase Hosting and served from example.com
  3. Backend on Kubernetes cluster behind Load Balancer with external static IP 1.2.3.4

I want to serve the backend from example.com/api or api.example.com

My best guess is to use Cloud DNS to connect IP adress and subdomain (or URL)

  • 1.2.3.4 -> api.exmple.com
  • 1.2.3.4 -> example.com/api

The problem is that Cloud DNS uses custom name servers, like this:

ns-cloud-d1.googledomains.com

So if I set Google default name servers I can reach Firebase hosting only, and if I use custom name servers I can reach only Kubernetes backend.

What is a proper way to be able to reach both api.example.com and example.com?

edit: As a temporary workaround i'm combining two default name servers and two custom name servers from cloud DNS, like this:

  • ns-cloud-d1.googledomains.com (custom)
  • ns-cloud-d2.googledomains.com (custom)
  • ns-cloud-b1.googledomains.com (default)
  • ns-cloud-b2.googledomains.com (default)

But if someone knows the proper way to do it - please post the answer.

2
I am not entirely sure but have you explored using an ExternalName service pointing to firebase & then ingress controller in Kubernetes pointing to Firebase using that service and backend using another service.Vishal Biyani
Interesting, I need to think about this, thanks. My first concern about this approach is that I will pay twice for firebase cdn AND kubernetes ingress traffic. And I will need to figure something out for SSL certificates because in my current solution Firebase has free "real" SSL and Kubernetes has self-signed SSL for ingress and of course user should not face "not secure" certificate in browser.Zhorzh Alexandr

2 Answers

1
votes

Approach 1:

example.com --> Firebase Hosting (A record)
api.example.com --> Kubernetes backend

Pro: Super-simple

Con: CORS request needed by browser before API calls can be made.

Approach 2:

example.com --> Firebase Hosting via k8s ExternalName service
example.com/api --> Kubernetes backend

Unfortunately from my own efforts to make this work with service type: ExternalName all I could manage is to get infinitely redirected, something which I am still unable to debug.

Approach 3:

example.com --> Google Cloud Storage via NGINX proxy to redirect paths to index.html
example.com/api --> Kubernetes backend

You will need to deploy the static files to Cloud Storage, with an NGINX proxy in front if you want SPA-like redirection to index.html for all routes. This approach does not use Firebase Hosting altogether.

The complication lies in the /api redirect which depends on which Ingress you are using.

Hope that helps.

0
votes

I would suggest creating two host paths. The first would be going to "example.com" using NodePort type. You can then use the External Name service for "api.exmple.com".