0

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.

I assume that is because they are sent to a different pod than the one originally servicing the request.

How can this be fixed?

This is my setup:

  • VueJS app (node.js-Server) running from a Docker image in kubernetes.
  • Service and endpoint in kubernetes above that.
  • nginx ingress in kubernetes as the next outward layer (see below).
  • haproxy firewall such that myapp.mydomain.com/ gets routed to the ingress on k8s.

This is an example call which gets a 404 returned: GET https://myapp.mydomain.com/js/chunk-d18c0136.7a3f0664.js

This is my service spec:

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}

This is my nginx ingress spec:

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: "nginx"
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
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                  

As a workaround we've configured the firewall to speak directly with only one pod, or running only one replica.

Setting session-stickyness "cookie" on the nginx ingress doesn't work.

1 Answer 1

1

Sorry, this was a complete red herring.

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 "most" requests returned a 404 - the node couldn't be found.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.