微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Nginx 入口控制器在带有路由前缀的 Node.js 应用程序中出错

如何解决Nginx 入口控制器在带有路由前缀的 Node.js 应用程序中出错

我在 Google Kubernetes Engine 上托管的 Kubernetes 集群中使用 Ingress Nginx 控制器。该应用程序是一个 Node.js 应用程序。

当我将我的应用与 Rollbar(记录器服务)集成时,我开始每约 15 秒(一周内 154K 次)发现重复性错误

Error: Cannot GET /

打印:

Error on Rollbar

Error details

我认为原因是我的 Node.js 应用程序在路由中使用了 /v1 前缀,即 / 路由不存在。

PS:Rollbar 在开发(本地)、测试(Heroku)和生产(GKE)环境中链接错误仅发生在生产中。

我的入口文件

apiVersion: extensions/v1beta1
kind: Ingress
Metadata:
    name: ingress-app
spec:
    rules:
        - host: api.company.com
          http:
              paths:
                  - path: /v1
                    backend:
                        serviceName: company-prod-v1-service
                        servicePort: 3000

Ingress 文档 says something about / endpoint,但我不太明白。

我需要删除这个错误。有哪位绝地大师能帮我解决这个错误吗?

提前致谢

[更新]

部署文件

apiVersion: apps/v1
kind: Deployment
Metadata:
    name: app-deploy-v1
    labels:
        app: app-v1
        version: 1.10.0-2
spec:
    selector:
        matchLabels:
            app: app-v1
    replicas: 1
    strategy:
        type: RollingUpdate
        rollingUpdate:
            maxUnavailable: 1
    minReadySeconds: 30
    progressDeadlineseconds: 60
    template:
        Metadata:
            labels:
                app: app-v1
                version: 1.10.0-2
        spec:
            serviceAccountName: gke-account
            containers:
                - name: app-container
                  image: registry.gitlab.com/company/app-back:1.10.0
                  lifecycle:
                      postStart:
                          exec:
                              command:
                                  - "/bin/sh"
                                  - "-c"
                                  - >
                                      if [ -f "$SECRETS_FOLDER/$APPLE_NOTIFICATION_KEY" ]; then
                                          cp $SECRETS_FOLDER/$APPLE_NOTIFICATION_KEY $APP_FOLDER;
                                      fi;
                - name: cloud-sql-proxy
                  image: gcr.io/cloudsql-docker/gce-proxy:1.17
                  command:
                      - "/cloud_sql_proxy"
                      - "-instances=thermal-petal-283313:us-east1:app-instance=tcp:5432"
                  securityContext:
                      runAsNonRoot: true
                  lifecycle:
                      preStop:
                          exec:
                              command: ["/bin/sleep","300"]
            imagePullSecrets:
                - name: registry-credentials

Ingress Controller Pod 文件(在安装命令中自动生成

 apiVersion: v1
kind: Pod
Metadata:
  creationTimestamp: "2021-06-16T03:08:53Z"
  generateName: ingress-Nginx-controller
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-Nginx
    app.kubernetes.io/name: ingress-Nginx
  name: ingress-Nginx-controller
  namespace: ingress-Nginx
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: replicaset
    name: ingress-Nginx-controller
  resourceVersion: "112544950"
  selfLink: /api/v1/namespaces/ingress-Nginx/pods/ingress-Nginx-controller
spec:
  containers:
    image: k8s.gcr.io/ingress-Nginx/controller:v0.46.0
    imagePullPolicy: IfNotPresent
    lifecycle:
      preStop:
        exec:
          command:
          - /wait-shutdown
    livenessProbe:
      failureThreshold: 5
      httpGet:
        path: /healthz
        port: 10254
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      successthreshold: 1
      timeoutSeconds: 1
    name: controller
    ports:
    - containerPort: 80
      name: http
      protocol: TCP
    - containerPort: 443
      name: https
      protocol: TCP
    - containerPort: 8443
      name: webhook
      protocol: TCP
    readinessProbe:
      failureThreshold: 3
      httpGet:
        path: /healthz
        port: 10254
        scheme: HTTP
      initialDelaySeconds: 10
      periodSeconds: 10
      successthreshold: 1
      timeoutSeconds: 1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。