Make Kubernetes Service Accessible Externally

9/17/2015

We have a private kubernetes cluster running on a baremetal CoreOS cluster (with Flannel for network overlay) with private addresses.

On top of this cluster we run a kubernetes ReplicationController and Service for elasticsearch. To enable load-balancing, this service has a ClusterIP defined - which is also a private IP address: 10.99.44.10 (but in a different range to node IP addresses).

The issue that we face is that we wish to be able to connect to this ClusterIP from outside the cluster. As far as we can tell this private IP is not contactable from other machines in our private network...

How can we achieve this?


The IP addresses of the nodes are:

 node 1  - 192.168.77.102
 node 2  - 192.168.77.103

.

and this is how the Service, RC and Pod appear with kubectl:

NAME            LABELS          SELECTOR              IP(S)           PORT(S)
elasticsearch   <none>          app=elasticsearch     10.99.44.10     9200/TCP


CONTROLLER     CONTAINER(S)    IMAGE(S)       SELECTOR            REPLICAS
elasticsearch  elasticsearch   elasticsearch  app=elasticsearch   1


NAME                       READY     STATUS    RESTARTS   AGE
elasticsearch-swpy1         1/1       Running   0          26m
-- DrGecko
coreos
docker
flannel
google-kubernetes-engine
kubernetes

2 Answers

9/26/2019

You can use nodeport, but also use hostport for some daemonsets and deployments and hostnetwork to give a pod total node network access

IIRC, if you have a recent enough kubernetes, each node can forward traffic to the internal network, so if you create the correct routing in your clients/switch, you can access the internal network by delivering those TCP/IP packages to one node. The node will then receive the package and SNAT+forward to the clusterIP or podIP.

Finally, barebone can use now MetalLB for kubernetes loadbalancer, that is mostly using this last feature in a more automatic and redundant way

-- higuita
Source: StackOverflow

9/18/2015

You need to set the type of your Service.

http://docs.k8s.io/v1.0/user-guide/services.html#external-services

If you are on bare metal, you don't have a LoadBalancer integrated. You can use NodePort to get a port on each VM, and then set up whatever you use for load-balancing to aim at that port on any node.

-- Tim Hockin
Source: StackOverflow