Kubernetes在同一子域中部署两个微服务会导致频繁和随机的404错误 [英] Kubernetes deployment of two microservices at same subdomain resulting in frequent and random 404 errors

查看:78
本文介绍了Kubernetes在同一子域中部署两个微服务会导致频繁和随机的404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Kubernetes部署,它由一个nodejs前端和一个nginx后端组成.我们发现,这两种部署在Kubernetes中分别运行良好,但是当它们都部署到前端时,几乎50%的时间都返回404.

We have a Kubernetes deployment consisting of a nodejs front end and an nginx backend. We're finding that the two deployments work fine in Kubernetes individually, but when they are both deployed requests to the front end return a 404 almost exactly 50% of the time.

很自然地假设我们的虚拟服务存在问题,但是基于vs/gateway的部署不足以引起问题的事实,似乎并非如此.看来,如果我们在后端部署另一个不相关的映像,则前端将继续正常工作而不会出现404错误.

It's natural to assume there is an issue with our virtual service, but this seems to not be the case, based on the fact that the deployment of the vs/gateway is not sufficient to cause the issue. It also seems that if we deploy a different, unrelated image in the backend, the front-end continues to work without 404 errors.

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

The app was originally generated via JHipster, and we manually separated the front-end and backend components. The front-end is nodejs, the backend is Java/nginx. The app works locally, but fails in a k8s deployment.

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

Also, our Kubernetes deployment is in Rancher.

实验似乎表明它与我们的后端部署中的某些内容有关,因此我在下面包括了我们的后端deployement.yaml:

Experiments seem to indicate it is related to something in our back-end deployment, so I'm including our backend deployement.yaml below:

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可以使您绊倒.确保它指向前端和后端的不同应用程序.

Each service needs to point to a different app. You can verify in Rancher that each service points to a different app. Check your yaml. If using Kustomize, the commonLabels:app can trip you up. Make sure it points to different apps for frontend and backend.

这篇关于Kubernetes在同一子域中部署两个微服务会导致频繁和随机的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆