<p>I have set up a simple Kubernetes load balancer service in front of a Node.js container, which should be exposing port 80, but I can't get a response out of it. <em>How can I debug how the load balancer is handling requests to port 80</em>? Are there logs I can inspect?</p>

<p>I have set up a load balancer service and a replication controller as described in the Kubernetes <a href="http://kubernetes.io/v1.1/examples/guestbook-go/README.html" rel="noreferrer">guestbook example</a>.</p>

<p>The service/load balancer spec is similar to this:</p>

<pre><code>{
   "kind":"Service",
   "apiVersion":"v1",
   "metadata":{
      "name":"guestbook",
      "labels":{
         "app":"guestbook"
      }
   },
   "spec":{
      "ports": [
         {
           "port":3000,
           "targetPort":"http-server"
         }
      ],
      "selector":{
         "app":"guestbook"
      },
      "type": "LoadBalancer"
   }
}
</code></pre>

<p>As for my hosting platform, I'm using AWS and the OS is CoreOS alpha (976.0.0). Kubectl is at version 1.1.2.</p>

<h1>Kubernetes Info</h1>

<pre><code>$ ~/.local/bin/kubectl --kubeconfig=/etc/kubernetes/kube.conf get pods
NAME            READY     STATUS    RESTARTS   AGE
busybox-sleep   1/1       Running   0          18m
web-s0s5w       1/1       Running   0          12h
$ ~/.local/bin/kubectl --kubeconfig=/etc/kubernetes/kube.conf get services
NAME         CLUSTER_IP   EXTERNAL_IP   PORT(S)   SELECTOR   AGE
kubernetes   10.3.0.1     &lt;none&gt;        443/TCP   &lt;none&gt;     1d
web          10.3.0.171
</code></pre>

<p>Here is the primary debugging document for Services:</p>

<p><a href="http://kubernetes.io/docs/user-guide/debugging-services/" rel="noreferrer">http://kubernetes.io/docs/user-guide/debugging-services/</a></p>

<p>LoadBalancer creates an external resource. What exactly that resource is depends on your Cloud Provider - some of them don't support it at all (in this case, you might want to try NodePort instead).</p>

<p>Both Google and Amazon support external load balancers. </p>

<p>Overall, when asking these questions it's extremely helpful to know if you are running on Google Container Engine, Google Compute Engine, Amazon Web Services, Digital Ocean, Vagrant, or whatever, because the answer depends on that. Showing all your configs and all your existing Kubnernetes resources (<code>kubectl get pods</code>, <code>kubectl get services</code>) along with your Dockerfiles or which images you are using will also help.</p>

<p>For Google (GKE or GCE), you would verify the load balancer exists:</p>

<pre><code>gcloud compute forwarding-rules list
</code></pre>

<p>The external load balancer will map port 80 to an arbitrary Node, but then the Kubernetes proxy will map that to an ephemeral port on the correct node that actually has a Pod with that label, then it will map to the container port. So you have to figure out which step along the way isn't working. Unfortunately all those kube-proxy and iptables jumps are quite difficult to follow, so usually I would first double check all my Pods exist and have labels that match the selector of the Service. I would double check that my container is exposing the right port, I am using the right name for the port, etc. You might want to create some other Pods that just make calls to the Service (using the environment variables or KubeDNS, see the Kubernetes service documentation if you don't know what I'm referring to) and verify it's accessible internally before debugging the load balancer.</p>

<p>Some other good debugging steps:</p>

<p>Verify that your Kubernetes Service exists:</p>

<pre><code>kubectl get services
kubectl get pods
</code></pre>

<p>Check your logs of your pod</p>

<pre><code>kubectl logs &lt;pod name&gt;
</code></pre>

<p>Check that your service is created internally by printing the environment variable for it</p>

<pre><code>kubectl exec &lt;pod name&gt; -- printenv GUESTBOOK_SERVICE_HOST
</code></pre>

<p>try creating a new pod and see if the service can be reached internally through GUESTBOOK_SERVICE_HOST and GUESTBOOK_SERVICE_PORT.</p>

<pre><code>kubectl describe pod &lt;pod name&gt;
</code></pre>

<p>will give the instance id of the pod, you can SSH to it and run Docker and verify your container is running, attach to it, etc. If you really want to get into the IP tables debugging, try</p>

<pre><code>sudo iptables-save
</code></pre>
