title: Connecting from K8S pod in GKE to a VM internal IP on Google Cloud Platform
body: <p>We have a requirement to connect from a POD in GKE to service running on a VM on it's internal IP address. </p>
  
  <p><a href="https://i.stack.imgur.com/nPr6k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nPr6k.png" alt="enter image description here"></a></p>
  
  <p>The K8s cluster and the VM are on different network so we setup VPC Peering between these nets: </p>
  
  <p><a href="https://i.stack.imgur.com/Ncviz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ncviz.png" alt="enter image description here"></a></p>
  
  <p>As how to point to an external IP, we applied a service without a selector as discussed here: </p>
  
  <p><a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors</a></p>
  
  <p>The POD should connect to the internal IP of the VM through this service, the service and endpoint description is: </p>
  
  <p>kubectl describe svc vm-proxy</p>
  
  <pre><code>Name:              vm-proxy
  Namespace:         test-environment
  Labels:            &lt;none&gt;
  Annotations:       &lt;none&gt;
  Selector:          &lt;none&gt;
  Type:              ClusterIP
  IP:                10.59.251.146
  Port:              &lt;unset&gt;  8080/TCP
  TargetPort:        8080/TCP
  Endpoints:         10.164.0.10:8080
  Session Affinity:  None
  Events:            &lt;none&gt;
  </code></pre>
  
  <p>Whereby the Endpoint, the internal IP of the VM is, en the 
  Service IP is allocated by K8s. </p>
  
  <p>The pod simply sets up an http connection to the IP of the Service, but connection is re-fused. (Connection timeout eventually). </p>
  
  <p>The use case is pretty straightforward, and documented on k8s documentation, giving the example of connecting to a DB running on a VM. However it doesn't work in our case, and we are not sure if our setup is wrong or this is simply not possible, using an internal IP of a VM. </p>