Expose kubernetes master service to host

6/22/2015

I'm trying my hands on kubernetes and come across very basic question. I have setup single node kubernetes on ubuntu running in VirtualBox. This is exactly what I have. My vagrant file is something like this (so on my mac I can have virtualbox running ubuntu)-

Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant"

  config.vm.define "app" do |d|

  d.vm.box = "ubuntu/trusty64"

  d.vm.hostname = "kubernetes"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  d.vm.network "private_network", ip: "192.168.20.10"

  d.vm.provision "docker"

  end
end

And to start the master I have init.sh something like this-

docker run --net=host -d gcr.io/google_containers/etcd:2.0.9 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data

docker run --net=host -d -v /var/run/docker.sock:/var/run/docker.sock \
gcr.io/google_containers/hyperkube:v0.18.2 /hyperkube kubelet \
    --api_servers=http://localhost:8080 \
    --v=2 \
    --address=0.0.0.0 \
    --enable_server \
    --hostname_override=127.0.0.1 \
    --config=/etc/kubernetes/manifests

docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v0.18.2 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2

wget http://storage.googleapis.com/kubernetes-release/release/v0.19.0/bin/linux/amd64/kubectl
sudo chmod +x ./kubectl

This brings up simple kubernetes running in vm. Now I can see kubernetes services running if I get services using kubectl-

kubernetes            component=apiserver,provider=kubernetes                          <none>                  10.0.0.2     443/TCP
kubernetes-ro         component=apiserver,provider=kubernetes                          <none>                  10.0.0.1     80/TCP

I can curl in ssh to 10.0.0.1 and see the result. But My question is how can I expose this kubernetes master service to host machine or when I deploy this thing on server, how can I make this master service available to public ip ?

-- Maulik
kubernetes

1 Answer

6/22/2015

To expose Kubernetes to the host machine, make sure you exposing the container ports to ubuntu, using the -p option in docker run. Then you should be able to access kubernetes like it was running on the ubuntu box, if you want it to be as if it were running on the host, then port forward the ubuntu ports to your host system. For deployment to servers there are many ways to do this, gce has it's own container engine backed by kubernetes in alpha/beta right now. Otherwise, if you want to deploy with the exact same system, most likely you'll just need the right vagrant provider and ubuntu box and everything should be the same as your local setup otherwise.

-- Christian Grabowski
Source: StackOverflow