Interconnect a Kubernetes cluster with a Docker network

9/22/2019

I am trying to enable communication between Kubernetes (K8s) pods and a Docker container but I cannot find how to do so on Windows. Help would be greatly appreciated.

Scenario description:

The n K8s pods are composed of one (and only) container: a Go microservice accessed by Postman at this time, itself supposed to access a database.

To enable a load-balanced access to the pods as one, a Kubernetes service is put on top, using a NodePort. So far everything is working.

But the K8s-Pod/Go-microservice <> Docker-container/db part do not see each other. The Go microservice obviously says the "db" cannot be resolved. The container db is itself in a user-defined docker network (called "mynw"); its type is a bridge.

Would anyone know how to acheive this in the simplest way? (I mean without third-party/tierce things, heavy proxy configuration, etc.)

Thanks!

-- willemavjc
containers
docker
kubernetes
networking
pod

2 Answers

9/22/2019

You can create a headless service in k8s, with an endpoint pointing to your database container. Then you have to direct your Go service to use that headless service as the db connection.

-- Burak Serdar
Source: StackOverflow

9/22/2019

On top of headless services mentioned by bserdar, you can also use services of type externalName if your database has a proper DNS name.

-- Alassane Ndiaye
Source: StackOverflow