Microservices from inside a Kubernetes pod to access external database

7/31/2019

I need a suggestion as right now I do not have a functional kube cluster. We are building a set of microservices which will be running on the on-premise Kubernetes cluster. All these microservices have to access and external(to this clusetr) oracle database and a Kafka instances. Both the services(DB and Kafka) will be in the same network but outside Kubernetes cluster. This is a customer ask and we can't help it.

All I could understand from different posts are:
1. Create a Service yaml with Type as ExternalName and then have to provide the name(CNAME) accordingly.

My question is, can I use a IP instead of CNAME here ? Since the database is within the same network it seems obvious to me though.

Or do I have to add further configurations ?

I could search so many posts from developers who were not able to configure it properly. Hence, little doubtful about the exact step.

Thanks is advance.

-- deb basu
kubernetes

1 Answer

7/31/2019

The best way to do that is using an endpoint where you create an object that gives you a name inside the cluster that points to an external IP address.

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

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

With that said the only point that remains is to be sure that the interna clúster network ranges don't conflict with your external network, because if you have for example on your cluster the range 10.0.0.0/8 for your pods and you use a subnetwork of that range also on the outside network for example 10.0.1.0/16 the pod should never reach the external service.

-- wolmi
Source: StackOverflow