简体   繁体   中英

Make k8s cluster services available to local docker containers

I'm used to connect to my cluster using telepresence and access cluster services locally.

Now, I need to make services in the cluster available to a group of applications that are running in docker containers locally . We can say that it's the inverse use case.

I've an app that is running in a docker container. It access services that are deploy using docker-compose . It has been done by using a network:

docker network create myNetwork
// Make app 1 to use it
docker network connect myNetwork app1
// App 2 uses docker compose, so myNetwork is defined in it and here I just:
docker-compose up

My app1 access correctly the containers/services running in app2 . However, I still need it to access a service from my cluster!

I've tried make a tunnel from my host to the cluster with telepresence and then try to access the service as if it were in my host. However it seems not to work. If I go into my app1 container and do a curl to see if the service name resolves:

curl: (6) Could not resolve host: my_cluster_service_name

Is my approach wrong? Am I missing an operation or consideration? How could I accomplish it?

Docker version: Docker version 19.03.8 for Mac

I've find a way to solve the problem.

Instead of trying to use telepresence as for the inverse use case, solution comes by using a port-forward with k9s . When creating it, it's important to do not leave the default interface, that is set to localhost , and put 0.0.0.0 instead to ensure that it listens traffic from all interfaces.

Then I've changed my containers from inside, making the services to point to my host's IP when trying to resolve the service names. Use the method that better fits your case for this: since it's not a production environment I just tried hardcoding my host IP manually to check if the connectivity was achieved.

To point to an specific service of your cluster you need to use different ports since they will be all mapped to your host with different port-forwards . Name resolving is no longer needed.

With this configuration, your container request will reach your host, where the port-forward routes it to the cluster. Connectivity is OK with this setup and the problem is solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM