Search code examples
dockerdocker-for-mac

Share localhost:port loadbalancer with kubernetes


Do you know if it is possible to share localhost:port with kubernetes.

I am running kubernetes in docker-for-mac, and when creating a loadbalancer - everything works great for containers running in kubernetes via localhost.

Sometime I like to test some code, in a container running just as a docker run - where I am opening ports with -p 8080:80 something.

Now the question is will it conflict with the localhost running k8s loadbalancer - if I run on ports not open to kubernetes loadbalancer?

My guess is, that it does not work - as I am experience some problems reaching ports running with docker run.

If it does not work, how do you docker run along side Kubernetes?


Solution

  • If you’re using the Kubernetes built into Docker (Edge) for Mac, it is the same Docker daemon, and docker run -p will publish ports on your host as normal. This should share a port space with services running outside Docker/Kubernetes and also with exposed Kubernetes services.

    You need to pick a different host port with your docker run -p option if you need to run a second copy of a service, whether the first one is another plain Docker container or a Kubernetes Service or a host process or something else.

    Remember that “localhost” is extremely context sensitive; I’d avoid using it in questions like this. If you docker run -p 8080:80 ... as you suggest, the host can make outbound calls to the container at localhost:8080; the container can make outbound calls to itself at localhost:80; and nothing in any Kubernetes pod or any other container can see the service at localhost on any port.