Nginx Ingress - 502 Bad Gateway - 连接到上游时失败(111:连接被拒绝) - Kubernetes

Jes*_*inn 5 digital-ocean kubernetes nginx-ingress

我收到来自 的以下错误ingress-nginx-controller,这最终给了我502 Bad Gateway. 我可以毫无错误地转发到我的 Nodejs 服务。

2020/05/30 21:31:12 [error] 485#485: *18798 connect() failed (111: Connection refused) while connecting to upstream, client: 177.183.249.235, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.244.0.249:3000/favicon.ico", host: "167.172.15.8", referrer: "http://167.172.15.8/"

我正在使用 Pulumi,以下是定义的服务:

export const frontendService = new k8s.core.v1.Service(config.appNameFrontend, {
  metadata: {
    namespace: namespace.metadata.name,
    labels: {
      app: config.appNameFrontend,
      service: config.appNameFrontend
    }
  },
  spec: {
    ports: [{
      name: "http",
      port: 80,
      targetPort: 3000
    }],
    selector: {
      app: config.appNameFrontend
    }
  }
})
`
Run Code Online (Sandbox Code Playgroud)

部署:

const frontendDeployment = new k8s.apps.v1.Deployment(`${config.appNameFrontend}-${config.version}`, {
  metadata: {
    namespace: namespace.metadata.name,
    labels: {
      app: config.appNameFrontend,
      version: config.version,
    },
  },
  spec: {
    replicas: 1,
    selector: {
      matchLabels: {
        app: config.appNameFrontend,
        version: config.version
      }
    },
    template: {
      metadata: {
        labels: {
          app: config.appNameFrontend,
          version: config.version
        }
      },
      spec: {
        serviceAccountName: frontendServiceAccount.metadata.name,
        containers: [{
          name: config.appNameFrontend,
          image: "registry.digitalocean.com/connecttv/connecttv-frontend:latest",
          imagePullPolicy: "Always",
          resources: {
            limits: {
              cpu: "1000m"
            },
            requests: {
              cpu: "100m"
            }
          },
          ports: [{
            containerPort: 3000
          }]
        }],
        restartPolicy: "Always",
        imagePullSecrets: [{
          name: pulumi.interpolate`${imagePullSecret.metadata.name}`
        }]
      }
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

最后是入口:

const frontendIngress = new k8s.networking.v1beta1.Ingress(`frontend-ingress-${config.projectName}-v1`, {
  metadata: {
    namespace: namespace.metadata.name,
    annotations: {
      "kubernetes.io/ingress.class": "nginx"
    }
  },
  spec: {
    rules: [
      {
        http: {
          paths: [
            {
              path: "/",
              backend: {
                serviceName: frontendService.metadata.name,
                servicePort: frontendService.spec.ports[0].port,
              },
            }
          ],
        },
      },
    ],
  },
});
Run Code Online (Sandbox Code Playgroud)

有什么想法会导致这种情况吗?

我使用0.32.0版本安装nginx ingress(digitalocean)。

但是,我将 修改deploy.yamlexternalTrafficPolicy: Clusterfrom local

Jes*_*inn 7

固定的。经常检查你的 dockerfile!它被设置为仅监听本地主机!!!!

  • 天哪,这给了我一个线索,我需要意识到 fastify 默认情况下只监听 127.0.0.1。浪费了2天时间 (3认同)