I want to setup web app using three components that i already have:
example.com
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.
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.
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".