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!
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.
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.