<p>When I create a deployment and a service in a Kubernetes Engine in GCP I get connection refused for no apparent reason.</p>
<p>The service creates a Load Balancer in GCP and all corresponding firewall rules are in place (allows traffic to port 80 from <code>0.0.0.0/0</code>). The underlying service is running fine, when I <code>kubectl exec</code> into the pod and <code>curl localhost:8000/</code> I get the correct response.</p>
<p>This deployment setting used to work just fine for other images, but yesterday and today I keep getting</p>
<pre><code>curl: (7) Failed to connect to 35.x.x.x port 80: Connection refused
</code></pre>
<p>What could be the issue? I tried deleting and recreating the service multiple times, with no luck.</p>
<pre><code>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
</code></pre>

<p>This turned out to be a dumb mistake on my part. The gunicorn server was using a bind to <code>127.0.0.1</code> instead of <code>0.0.0.0</code>, so it wasn't accessible from outside of the pod, but worked when I <code>exec</code>-ed into the pod.</p>
<p>The fix in my case was changing the entrypoint of the Dockerfile to</p>
<pre><code>CMD [ &quot;gunicorn&quot;, &quot;server:app&quot;, &quot;-b&quot;, &quot;0.0.0.0:8000&quot;, &quot;-w&quot;, &quot;3&quot; ]
</code></pre>
<p>rebuilding the image and updating the deployment.</p>
