How to access google cloud instances from kubernetes containers

4/26/2017

I have k8s cluster in Google Cloud and frontend/api containers there. In addition to that I have ElasticSearch cluster (es1,es2) in Google Cloud but not under k8s.

I can access api container by name 'api' from container 'frontend'. I can access es1 from es2 by name 'es1'.

What is a right way to access es cluster by names like es1,es2 from containers api/frontend ?

Thanks!

-- Nick
google-compute-engine
kubernetes

2 Answers

6/5/2017

Create the Kubernetes Cluster (GKE) in the same network/subnetwork like your instances, then you can connect the internal Ip´s of your GCE instances from your k8s pods.

-- Marcel Gä
Source: StackOverflow

4/28/2017

If you want to refer to resources outside of your Kubernetes cluster as if they are inside the cluster, the simplest option is probably to assign each ElasticSearch instance a static IP, and then specify a Kubernetes Service with manual Endpoints:

https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors

You can add an Endpoint entry for each es instance you have. Now your internal cluster DNS will resolve and load-balance for your es instances as if they were pods in the cluster.

You create endpoints like this (note the lack of selector on the Service):

kind: Endpoints
apiVersion: v1
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: 1.2.3.4
    ports:
      - port: 9376
---

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Now you can access the service using my-service.my-namespace.svc.cluster.local as normal.

-- Symmetric
Source: StackOverflow