Zhorzh Alexandr
Zhorzh Alexandr

Reputation: 1469

How to serve Kubernetes backend and Firebase hosting frontend from the same domain name?

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)

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:

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

Upvotes: 3

Views: 1826

Answers (2)

Jonathan Lin
Jonathan Lin

Reputation: 20724

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.

Upvotes: 1

Jason
Jason

Reputation: 638

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".

Upvotes: 0

Related Questions