<p>I have created a kubernetes service: </p>

<pre><code>[root@Infra-1 kubernetes]# kubectl describe service gitlab 
Name:           gitlab
Namespace:      default
Labels:         name=gitlab
Selector:       name=gitlab
Type:           NodePort
IP:         10.254.101.207
Port:           http    80/TCP
NodePort:       http    31982/TCP
Endpoints:      172.17.0.4:80
Port:           ssh 22/TCP
NodePort:       ssh 30394/TCP
Endpoints:      172.17.0.4:22
Session Affinity:   None
No events.
</code></pre>

<p>However, am unable to connect to connect to the Endpoint, not even from the shell on the node host:</p>

<pre><code> [root@Infra-2 ~]# wget 172.17.0.4:80
 --2015-12-08 20:22:27--  http://172.17.0.4:80/
 Connecting to 172.17.0.4:80... failed: Connection refused.
</code></pre>

<p>Calling <code>wget localhost:31982</code> on the NodePort also gives a <code>Recv failure: Connection reset by peer</code> and the kube-proxy logs error messages:</p>

<pre><code> Dec 08 20:13:41 Infra-2 kube-proxy[26410]: E1208 20:13:41.973209   26410 proxysocket.go:100] Dial failed: dial tcp 172.17.0.4:80: connection refused
 Dec 08 20:13:41 Infra-2 kube-proxy[26410]: E1208 20:13:41.973294   26410 proxysocket.go:100] Dial failed: dial tcp 172.17.0.4:80: connection refused
 Dec 08 20:13:41 Infra-2 kube-proxy[26410]: E1208 20:13:41.973376   26410 proxysocket.go:100] Dial failed: dial tcp 172.17.0.4:80: connection refused
 Dec 08 20:13:41 Infra-2 kube-proxy[26410]: E1208 20:13:41.973482   26410 proxysocket.go:100] Dial failed: dial tcp 172.17.0.4:80: connection refused
 Dec 08 20:13:41 Infra-2 kube-proxy[26410]: E1208 20:13:41.973494   26410 proxysocket.go:134] Failed to connect to balancer: failed to connect to an endpoint.
</code></pre>

<p>What could be the reason for this failure? </p>

<p>Here is my service configuration file <a href="http://pastebin.com/RriYPRg7" rel="nofollow">http://pastebin.com/RriYPRg7</a>, a slight modification of <a href="https://github.com/sameersbn/docker-gitlab/blob/master/kubernetes/gitlab-service.yml" rel="nofollow">https://github.com/sameersbn/docker-gitlab/blob/master/kubernetes/gitlab-service.yml</a></p>

<p>It's actually the Pod or Replication Controller that is having the issue because it is not forwarding to the service. Perhaps post that config or make sure it has port specified and its containers' processes are listening to the right port</p>

<p><strong>Original</strong></p>

<p>It's the <code>NodePort</code> that is actually exposed outside of the pod. <code>Port</code> is the port on the NAT network within the node and  <code>Port</code> is what the process inside the container should bind to, the usually using service discovery. Other pods will talk to that pod on the <code>NodePort</code>.  If you want to set the <code>NodePort</code> explicitly for say a web server, then in you Pod's definition or a replication controller or service definition, explicitly set <code>NodePort</code> to the desired port.</p>

<p>There for <code>Port: 80</code> would be say nginx inside a container listening on port 80, then <code>NodePort: 4980</code> would be the exposed port. So you would <code>wget &lt;Node IP&gt;:4980</code>.</p>

<p>As far as fixing your particular situation, I recommend not complicating it as much and explicitly set <code>TargetPort</code> and <code>NodePort</code>.</p>
