连接被拒绝到 Kubernetes 中的 GCP LoadBalancer

Rob*_*cok 6 google-cloud-platform kubernetes google-kubernetes-engine

当我在 GCP 的 Kubernetes Engine 中创建部署和服务时,连接被无缘无故拒绝。

该服务在 GCP 中创建了一个负载均衡器,并且所有相应的防火墙规则都已就位(允许从 到端口 80 的流量0.0.0.0/0)。当我kubectl exec进入 pod 并curl localhost:8000/得到正确响应时,底层服务运行良好。

此部署设置曾经适用于其他图像,但昨天和今天我不断收到

curl: (7) Failed to connect to 35.x.x.x port 80: Connection refused
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?我多次尝试删除并重新创建该服务,但没有成功。

kind: Service
apiVersion: v1
metadata:
  name: my-app
spec:
  selector:
    app: app 
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8000
---
apiVersion: apps/v1beta2 
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: my-app
        image: gcr.io/myproject/my-app:0.0.1
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
Run Code Online (Sandbox Code Playgroud)

Rob*_*cok 7

事实证明,这对我来说是一个愚蠢的错误。gunicorn 服务器使用的是 bind to127.0.0.1而不是0.0.0.0,因此无法从 pod 外部访问它,但是当我exec进入 pod时它可以工作。

在我的情况下的修复是将 Dockerfile 的入口点更改为

CMD [ "gunicorn", "server:app", "-b", "0.0.0.0:8000", "-w", "3" ]
Run Code Online (Sandbox Code Playgroud)

重建映像并更新部署。