search

Home  >  Q&A  >  body text

VueJS application not loading js file in kubernetes

I have a VueJS application running in a Docker image in kubernetes. Once multiple replicas/pods exist, clients are unable to load the application - many (but not all) calls to load files return 404.

I think this is because they are being sent to a different Pod than the Pod that originally serviced the request.

how to solve this problem?

This is my setup:

This is an example call that returns 404: Get https://myapp.mydomain.com/js/chunk-d18c0136.7a3f0664.js

This is my service specification:

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 entry specification:

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 configure the firewall to communicate directly with only one Pod, or only run one replica.

Setting the session sticky "cookie" on the nginx portal does not work.

P粉936509635P粉936509635310 days ago528

reply all(1)I'll reply

  • P粉403549616

    P粉4035496162024-03-30 09:31:57

    Sorry, this is a complete red herring.

    Ultimately, the problem was a typo in the external proxy routing - only two of the six nodes were configured correctly and accessible. That's why "most" requests return 404 - Node Not Found.

    reply
    0
  • Cancelreply