Accessing kubernetes running inside docker in a guest OS from the host OS

1/20/2016

I'm trying to access the kubernetes api exposed inside a guest OS provisionned by Vagrant from the host OS. The Vagrantfile exposes all ports of the guest OS through a private network and also forward the port 8080 like this :

config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "private_network", ip: "192.168.50.4"

When following the kubernetes getting started guide with docker, I can't access the kubernetes api from the host OS through :

but the api are accessible from the guest OS at http://127.0.0.1:8080 only...

When running nginx from the guest OS like this

docker run -d -p 8080:80 nginx

the nginx server is accessible from the host OS at both http://127.0.0.1:8080 and http://192.168.50.4:8080

I'm wondering how what parameter is missing from the getting started guide to run kubernetes in docker and access it from the host OS through the private network setup wih vagrant (just like nginx) ?

-- avianey
docker
kubernetes
vagrant

1 Answer

4/12/2016

You need to configure an ExternalIP per the services spec at http://kubernetes.io/docs/user-guide/services/#external-ips

When configuring your service you'll want to include a section with something like the following (in JSON, you may prefer yaml).

{ "kind": "Service", "apiVersion": "v1", "metadata": { "name": "my-service" }, "spec": { "selector": { "app": "MyApp" }, "ports": [ { "name": "http", "protocol": "TCP", "port": 8080, "targetPort": 8080 } ], "externalIPs" : [ 192.168.50.4" ] } }

-- mgreg
Source: StackOverflow