<p>First off, let me say that I'm fairly new to Kubernetes and Microservices architecture in general. Let me also say that this is more of a high-level architectural question versus seeking prescriptive, how-to advice related to the technology. I think I can figure the implementation details out, but I'm unsure what mechanisms exist to get me to where I want to go.</p>

<h3>Application overview</h3>

<p>Simple "e-commerce" sample application running on a K8s cluster. SPA Front end, with .NET Core services for the API.</p>

<h3>Client (Front End)</h3>

<p>Angular SPA built and deployed to an NGinx container that serves up the Angular App as a static site. It's running as a <code>LoadBalancer</code> service on the cluster. </p>

<h3>Services (Back End)</h3>

<p>Two simple services running as <code>ClusterIP</code> in the cluster. Let's call them Product and Order. </p>

<h3>Problem</h3>

<p>When the SPA is deployed, it's making requests to the services from the <em>user's browser</em> versus the container. The services aren't running in a <code>LoadBalancer</code> configuration, so they're not exposed outside the cluster. What's the best practice here for getting the client application talking to the services? Specifically:</p>

<ul>
<li>Do I really need to expose every microservice externally? </li>
<li>Is there some kind of proxy technique, where I can expose a single <code>&lt;cluster&gt;/api</code> endpoint, that routes to the appropriate backend service?</li>
<li>Does Angular Universal (aka Server-side Rendering) have a part to play here?</li>
<li>Any referenceable repos I can look at for an example?</li>
</ul>

<p>I've searched through SO and have found similar questions, but none that ask exactly this question. I'll gladly delete this question if someone points me to an existing one that enlightens me.</p>

tobyb
<blockquote>
  <p>Do I really need to expose every microservice externally? </p>
</blockquote>

<p>No, you shouldn't.</p>

<blockquote>
  <p>Is there some kind of proxy technique, where I can expose a single /api endpoint, that routes to the appropriate backend service?</p>
</blockquote>

<p>Standard way is to use nginx as a proxy.</p>

<blockquote>
  <p>Any referenceable repos I can look at for an example?</p>
</blockquote>

<p>You can check my toy project:</p>

<ul>
<li>Nginx part here - <a href="https://github.com/taleodor/mafia-vue/tree/master/nginx" rel="nofollow noreferrer">https://github.com/taleodor/mafia-vue/tree/master/nginx</a></li>
<li>Deployment wrapper project - <a href="https://github.com/taleodor/mafia-deployment" rel="nofollow noreferrer">https://github.com/taleodor/mafia-deployment</a></li>
<li>Write-up how everything fits together - <a href="https://itnext.io/building-kubernetes-cicd-pipeline-with-github-actions-argocd-and-reliza-hub-e7120b9be870" rel="nofollow noreferrer">https://itnext.io/building-kubernetes-cicd-pipeline-with-github-actions-argocd-and-reliza-hub-e7120b9be870</a></li>
</ul>

<p>Specifically, this is how you reference back-end api in nginx from the toy project above (note it's using websockets, which may not be the case for you):</p>

<pre><code>    location /api {
        proxy_pass http://backend;
        proxy_set_header Host            $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header        X-Forwarded-Proto $http_x_forwarded_proto; # aws version - essentially this sets https schema

        # enable WebSockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
</code></pre>
