<p>I have a VueJS app running out of a Docker image in kubernetes. As soon as there is more than one replica / pod the client cannot load the app - many, but not all, calls to load files return a 404.</p>
<p>I assume that is because they are sent to a different pod than the one originally servicing the request.</p>
<p>How can this be fixed?</p>
<p>This is my setup:</p>
<ul>
<li>VueJS app (node.js-Server) running from a Docker image in kubernetes.</li>
<li>Service and endpoint in kubernetes above that.</li>
<li>nginx ingress in kubernetes as the next outward layer (see below).</li>
<li>haproxy firewall such that myapp.mydomain.com/ gets routed to the ingress on k8s.</li>
</ul>
<p>This is an example call which gets a 404 returned:
GET <a href="https://myapp.mydomain.com/js/chunk-d18c0136.7a3f0664.js" rel="nofollow noreferrer">https://myapp.mydomain.com/js/chunk-d18c0136.7a3f0664.js</a></p>
<p>This is my service spec:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: ${CI_PROJECT_NAME}-${CI_BUILD_REF_SLUG_SHORT}
  labels:
    app: ${CI_ENVIRONMENT_SLUG}
spec:
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP
      name: ${CI_PROJECT_NAME}-${CI_BUILD_REF_SLUG}
  selector:
    app: ${CI_ENVIRONMENT_SLUG}
</code></pre>
<p>This is my nginx ingress spec:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ${CI_PROJECT_NAME}-${CI_BUILD_REF_SLUG_SHORT}
  labels:
    app: ${CI_ENVIRONMENT_SLUG}
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/affinity: &quot;cookie&quot;
    nginx.ingress.kubernetes.io/proxy-connect-timeout: &quot;30&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;3600&quot;
    nginx.ingress.kubernetes.io/proxy-read-timeout: &quot;3600&quot;
spec:
  defaultBackend:
    service:
      name: ${CI_PROJECT_NAME}-${CI_BUILD_REF_SLUG_SHORT}
      port:
        number: 80
  rules:
    - host: ${CI_APPLICATION_HOST}
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: ${CI_PROJECT_NAME}-${CI_BUILD_REF_SLUG_SHORT}
                port:
                  number: 80                  
</code></pre>
<p>As a workaround we've configured the firewall to speak directly with only one pod, or running only one replica.</p>
<p>Setting session-stickyness &quot;cookie&quot; on the nginx ingress doesn't work.</p>

Neil
<p>Sorry, this was a complete red herring.</p>
<p>In the end, the problem was a typo in the external proxy routing - only two of six nodes were correctly configured and reachable. That's why &quot;most&quot; requests returned a 404 - the node couldn't be found.</p>
