<p>Ok, so currently I've got kubernetes master up and running on AWS EC2 instance, and a single worker running on my laptop:</p>

<pre><code>$ kubectl get nodes
NAME            STATUS    ROLES     AGE       VERSION
master          Ready     master    34d       v1.9.2
worker          Ready     &lt;none&gt;    20d       v1.9.2
</code></pre>

<p>I have created a Deployment using the following configuration:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hostnames
  labels:
    app: hostnames-deployment
spec:
  selector:
    matchLabels:
      app: hostnames
  replicas: 1
  template:
    metadata:
      labels:
        app: hostnames
    spec:
      containers:
      - name: hostnames
        image: k8s.gcr.io/serve_hostname
        ports:
        - containerPort: 9376
          protocol: TCP
</code></pre>

<p>The deployment is running:</p>

<pre><code>$ kubectl get deployment
NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hostnames      1         1         1            1           1m
</code></pre>

<p>A single pod has been created on the worker node:</p>

<pre><code>$ kubectl get pods
NAME                           READY     STATUS    RESTARTS   AGE
hostnames-86b6bcdfbc-v8s8l     1/1       Running   0          2m
</code></pre>

<p>From the worker node, I can curl the pod and get the information:</p>

<pre><code>$ curl 10.244.8.5:9376
hostnames-86b6bcdfbc-v8s8l
</code></pre>

<p>I have created a service using the following configuration:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: hostnames-service
spec:
  selector:
    app: hostnames
  ports:
  - port: 80
    targetPort: 9376
</code></pre>

<p>The service is up and running:</p>

<pre><code>$ kubectl get svc
NAME                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
hostnames-service   ClusterIP   10.97.21.18      &lt;none&gt;        80/TCP         1m
kubernetes          ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP        34d
</code></pre>

<p>As I understand, the service should expose the pod cluster-wide and I should be able to use the service IP to get the information pod is serving from any node on the cluster.</p>

<p>If I curl the service from the worker node it works just as expected:</p>

<pre><code>$ curl 10.97.21.18:80
hostnames-86b6bcdfbc-v8s8l
</code></pre>

<p>But if I try to curl the service from the master node located on the AWS EC2 instance, the request hangs and gets timed out eventually:</p>

<pre><code>$ curl -v 10.97.21.18:80
* Rebuilt URL to: 10.97.21.18:80/
*   Trying 10.97.21.18...
* connect to 10.97.21.18 port 80 failed: Connection timed out
* Failed to connect to 10.97.21.18 port 80: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to 10.97.21.18 port 80: Connection timed out
</code></pre>

<p><strong>Why can't the request from the master node reach the pod on the worker node by using the Cluster-IP service?</strong></p>

<p>I have read quite a bit of articles regarding kubernetes networking and the official kubernetes services documentation and couldn't find a solution.</p>

<p>Depends of which mode you using it working different in details, but conceptually same.</p>

<p>You trying to connect to 2 different types of addresses - the pod IP address, which is accessible from the node, and the virtual IP address, which is accessible from pods in the Kubernetes cluster.</p>

<p>IP address of the service is <strong>not</strong> an IP address on some pod or any other subject, that is a virtual address which mapped to pods IP address based on rules you define in service and it managed by <code>kube-proxy</code> daemon, which is a part of Kubernetes. </p>

<p>That address specially desired for communication inside a cluster for make able to access the pods behind a service without caring about how much replicas of pod you have and where it actually working, because service IP is static, unlike pod's IP. </p>

<p>So, service IP address desired to be available from other pod, not from nodes. </p>

<p>You can read in <a href="https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies" rel="nofollow noreferrer">official documentation</a> about how the Service Virtual IPs works.</p>
