Debugging LoadBalancer on Google Container Engine

Setting up a Kubernetes LoadBalancer for your pods on Google Container Engine is very easy. Just define a simple YAML or JSON file and do: kubectl create -f web-service.yaml.

apiVersion: v1 kind: Service metadata: name: web labels: name: web app: web spec: type: LoadBalancer loadBalancerIP: ports: - port: 80 targetPort: 3000 protocol: TCP selector: name: web app: web

However I had the problem that the LoadBalancer was always refusing a connection, even when the pod was running and answering on its nodes ephemeral IP. After a lot of experimenting and searching in the wrong place, I found that the targetPort of the LoadBalancer needs to be the port of the app running INSIDE the container - in this case port 3000.

I was working under the assumption that since I had already mapped the apps port 3000 to host port 80 in the container spec, the LoadBalancer would have to target port 80.