VueJS application not loading js file in kubernetes
P粉936509635
P粉936509635 2024-03-29 16:00:27
0
1
415

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:

  • VueJS applications (node.js-Server) run from Docker images in kubernetes.
  • Services and endpoints in kubernetes above.
  • The nginx ingress into Kubernetes serves as the next outward layer (see below).
  • haproxy firewall to route myapp.mydomain.com/ to the ingress on k8s.

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粉936509635
P粉936509635

reply all(1)
P粉403549616

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!