<p>I have a small <strong>java</strong> webapp comprising of three microservices - <strong>api-service</strong>,<strong>book-service</strong> and <strong>db-service</strong> all of which are deployed on a kubernetes cluster locally using minikube.</p>

<p>I am planning to keep separate UIs for <strong>api-service</strong> and <strong>book-service</strong> , with the common static files served from a separate pod, probably an <code>nginx:alpine</code> image.</p>

<p>I was able to create a front end that serves the static files from <code>nginx:alpine</code> referring to this <a href="https://www.linkedin.com/pulse/serve-static-files-from-docker-via-nginx-basic-example-arun-kumar" rel="noreferrer">tutorial.</a> </p>

<p>I would like to use <a href="https://github.com/kubernetes/ingress-nginx" rel="noreferrer"><code>ingress-nginx</code></a> controller for routing requests to the two services.</p>

<p>The below diagram crudely shows where I am now.</p>

<p>I am confused as to where I should place the pod that serves the static content, and how to connect it to the ingress resource.I guess that keeping a front end pod before ingress defeats the purpose of ingress-nginx controller. What is the best practice to serve static files. Appreciate any help. Thanks.</p>

<p><a href="https://i.stack.imgur.com/i86IZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/i86IZ.png" alt="enter image description here"></a> </p>

<p>Looks like you are confusing the fact that users, browsing online, will trigger standard requests to both "download" your static content, <strong>and</strong> use your 2 APIs (book and api). It's not the NGINX service serving the static content that is accessing your APIs, but the users browsers/applications, and they do that exactly the same for both static content and APIs (former has more/specific headers and data, like auth...).</p>

<p>On your diagram you'll want to put your new <code>static-service</code> at the exact same level as your <code>book-service</code> and <code>api-service</code>, ie <em>behind</em> the ingress. But your <code>static-service</code> won't have a link with the <code>db-service</code> like the other 2. Then just complete your ingress rules, with the static-service at the end as in this example:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: your-global-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /book-service
        backend:
          serviceName: book-service
          servicePort: 80
      - path: /api-service
        backend:
          serviceName: api-service
          servicePort: 80
      - path: /
        backend:
          serviceName: static-service
          servicePort: 80
</code></pre>

<p>You'll have to adjust your services names and ports, and pick the paths you want your users to access your APIs, in the example above you'd have:</p>

<ul>
<li><code>foo.bar.com/book-service</code> for your book-service</li>
<li><code>foo.bar.com/api-service</code> for the api-service</li>
<li><code>foo.bar.com/</code> ie everything else going to the static-service</li>
</ul>
