Unable to expose Kubernetes service on Bare Metal "Localhost"

12/10/2017

I am new to Kubernetes and have a basic question. I installed the Canonical Distribution of Kubernetes on a bare metal Ubuntu "Localhost" setup with LXD.

I am able to run a simple deployment/service for a NGINX cluster. However, I am confused as to how I can actually expose it externally using my server hostip.

For instance:

kubectl run my-nginx --image=nginx --replicas=3 --port=80
kubectl expose deployment my-nginx --type=NodePort
kubectl describe services my-nginx --> Shows NodePort as 31198

I can successfully run a CURL to any of the Worker Nodes:

curl 10.112.134.139:31198
curl 10.112.134.41:31198

However, my hostip is 192.168.X.Y. How can I actually expose this so I can access using the HOSTIP?

-- ahsanshah
kubernetes

1 Answer

12/10/2017

From what you describe, it looks like, in your local environment, configured a "containerized cluster". Therefore, you can access the NodePort accessing these containerized worker nodes, but the host IP itself (as there is nothing configured in that local host, right?).

So, what you would need to do is to establish a way to forward traffic from the Host to the "containerized cluster", so the NodePort is accessible.

One way that comes to mind would be, in the machine you are trying to access from, to configure a route like this

10.112.134.0/24 - gateway 192.168.X.Y

   sudo route add -net 10.112.134.0/24 gw 192.168.X.Y

Probably, you may need to check that the sysctl rule net.ip4.forward is enabled.

-- Javier Salmeron
Source: StackOverflow