Kubernetes 在同一子域中部署两个微服务导致频繁和随机的 404 错误

Kubernetes deployment of two microservices at same subdomain resulting in frequent and random 404 errors

我们有一个由 nodejs 前端和 nginx 后端组成的 Kubernetes 部署。我们发现这两个部署在 Kubernetes 中单独运行良好,但是当它们都部署到前端时 return 404 几乎正好是 50% 的时间。

很自然地假设我们的虚拟服务存在问题,但事实似乎并非如此,因为 vs/gateway 的部署不足以导致问题。似乎如果我们在后端部署一个不同的、不相关的图像,前端会继续工作而不会出现 404 错误。

app最初是通过JHipster生成的,我们手动分离了前后端组件。前端是nodejs,后端是Java/nginx。该应用程序在本地运行,但在 k8s 部署中失败。

此外,我们的 Kubernetes 部署在 Rancher 中。

实验似乎表明它与我们后端部署中的某些东西有关,所以我在下面包括了我们的后端 deployement.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ourapp-be-custom-mount
spec:
  revisionHistoryLimit: 3
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    spec:
      containers:
        - name: ourapp-be-custom-mount
          image: "IMAGE_SET_BY_OVERLAYS_KUSTOMIZATION"
          envFrom:
            - configMapRef:
                name: ourapp-be-config
          ports:
          - name: http
            containerPort: 8080
          resources:
            limits:
              cpu: "0.5"
              memory: "2048Mi"
            requests:
              cpu: "0.1"
              memory: "64Mi"
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: /usr/share/h2/data
              name: ourapp-db-vol01-custom-mount

          securityContext:
            runAsNonRoot: true
            runAsUser: 1000
      imagePullSecrets:
        - name: regcred-nexus
      volumes:
      - name: ourapp-db-vol01-custom-mount
        persistentVolumeClaim:
          claimName: ourapp-db-pvc-volume01-custom-mount
      terminationGracePeriodSeconds: 30

每项服务需要指向不同的应用程序。您可以在 Rancher 中验证每个服务是否指向不同的应用程序。检查你的 yaml。如果使用 Kustomize,commonLabels:app 可能会绊倒你。确保它指向前端和后端的不同应用程序。