<p>I am trying to setup connection to my databases which reside outside of GKE cluster from within the cluster.</p>

<p>I have read various tutorials including 
<a href="https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services" rel="nofollow noreferrer">https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services</a>
and multiple SO questions though the problem persists.</p>

<p>Here is an example configuration with which I am trying to setup kafka connectivity:</p>

<pre><code>---
kind: Endpoints
apiVersion: v1
metadata:
  name: kafka
subsets:
  - addresses:
      - ip: 10.132.0.5
    ports:
      - port: 9092

---
kind: Service
apiVersion: v1
metadata:
  name: kafka
spec:
  type: ClusterIP
  ports:
  - port: 9092
    targetPort: 9092
</code></pre>

<p>I am able to get some sort of response by connecting directly via <code>nc 10.132.0.5 9092</code> from the node VM itself, but if I create a pod, say by <code>kubectl run -it --rm --restart=Never alpine --image=alpine sh</code> then I am unable to connect from within the pod using <code>nc kafka 9092</code>. All libraries in my code fail by timing out so it seems to be some kind of routing issue.</p>

<p>Kafka is given as an example, I am having the same issues connecting to other databases as well.</p>

tna0y
<p>Solved it, the issue was within my understanding of how GCP operates.</p>

<p>To solve the issue I had to add a firewall rule which allowed all incoming traffic from internal GKE network. In my case it was <code>10.52.0.0/24</code> address range.</p>

<p>Hope it helps someone.</p>
