<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>In addition to "NodePort" types of services there are some additional ways to be able to interact with kubernetes services from outside of cluster. Maybe they will be more "natural" and easy:</p>

<ul>
<li>Use service type "LoadBalancer". It works only for some cloud providers and will not work for virtualbox for example, but I think it will be good to know about that feature. In that case you will get not only "internal cluster-only" ip address for your service but also externally configured load balancer to access it (in aws/gce etc.) <a href="http://kubernetes.io/v1.1/docs/user-guide/services.html#type-loadbalancer" rel="nofollow">Link to the documentation</a></li>
<li>Use one of the latest features called "ingress". Here is description from manual <strong>"An Ingress is a collection of rules that allow inbound connections to reach the cluster services. It can be configured to give services externally-reachable urls, load balance traffic, terminate SSL, offer name based virtual hosting etc."</strong>. <a href="http://kubernetes.io/v1.1/docs/user-guide/ingress.html" rel="nofollow">Link to the documentation</a></li>
<li>If kubernetes is not strict requirements and you can switch to latest openshift origin (which is "kubernetes on steroids") you can use origin feature called "router".

<ul>
<li><a href="https://docs.openshift.org/latest/architecture/index.html" rel="nofollow">Information about openshift origin</a>. </li>
<li><a href="https://docs.openshift.org/latest/architecture/core_concepts/routes.html" rel="nofollow">Information about openshift origin routes</a></li>
</ul></li>
</ul>
