<p>I want to setup web app using three components that i already have:</p>

<ol>
<li>Domain name registered on domains.google.com</li>
<li>Frontend web app hosted on Firebase Hosting and served from <code>example.com</code></li>
<li>Backend on Kubernetes cluster behind Load Balancer with external static IP <code>1.2.3.4</code></li>
</ol>

<p>I want to serve the backend from <code>example.com/api</code> or <code>api.example.com</code></p>

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

<ul>
<li><code>1.2.3.4</code> -> <code>api.exmple.com</code></li>
<li><code>1.2.3.4</code> -> <code>example.com/api</code></li>
</ul>

<p>The problem is that Cloud DNS uses custom name servers, like this:</p>

<pre><code>ns-cloud-d1.googledomains.com
</code></pre>

<p>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.</p>

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

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

<ul>
<li><code>ns-cloud-d1.googledomains.com</code> (custom)</li>
<li><code>ns-cloud-d2.googledomains.com</code> (custom)</li>
<li><code>ns-cloud-b1.googledomains.com</code> (default)</li>
<li><code>ns-cloud-b2.googledomains.com</code> (default)</li>
</ul>

<p>But if someone knows the proper way to do it - please post the answer.</p>

<p><strong>Approach 1:</strong></p>

<pre><code>example.com --&gt; Firebase Hosting (A record)
api.example.com --&gt; Kubernetes backend
</code></pre>

<p>Pro: Super-simple</p>

<p>Con: CORS request needed by browser before API calls can be made.</p>

<p><strong>Approach 2:</strong></p>

<pre><code>example.com --&gt; Firebase Hosting via k8s ExternalName service
example.com/api --&gt; Kubernetes backend
</code></pre>

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

<p><strong>Approach 3:</strong></p>

<pre><code>example.com --&gt; Google Cloud Storage via NGINX proxy to redirect paths to index.html
example.com/api --&gt; Kubernetes backend
</code></pre>

<p>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.</p>

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

<p>Hope that helps.</p>
