LoadBalancer is not accessible from outside of cluster

5/5/2019

For testing I created Kubernetes on single node by using Virtualbox. I created one Pod listening on port 4646, then I created LoadBalancer for that Pod.

Yaml file for Pod:

apiVersion: v1
kind: Pod
metadata:
  name: simple-app
  labels:
    app: simple-app
spec:
  containers:
    ...
    name: test-flask-app
    ports:
    - containerPort: 4646

Yaml file for LoadBalancer:

apiVersion: v1
kind: Service
metadata:
  name: simple-app-lb
spec:
  type: LoadBalancer
  ports:
  - port: 88
    protocol: TCP
    targetPort: 4646
  selector:
    app: simple-app

Output of command kubectl get nodes -o wide:

NAME     STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
server   Ready    master   20h   v1.14.1   10.0.2.8      <none>        Ubuntu 18.04.2 LTS   4.15.0-48-generic   docker://18.6.2

Output of command kubectl get all

NAME             READY   STATUS    RESTARTS   AGE
pod/simple-app   1/1     Running   5          20h

NAME                    TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/kubernetes      ClusterIP      10.96.0.1      <none>        443/TCP        20h
service/simple-app-lb   LoadBalancer   10.98.241.39   <pending>     88:32319/TCP   20h

On other virtual machine that is located in the same network I'd like to get an access to LoadBalancer by IP address of machine with Kubernetes and by port 88. If I run the next command I get the output below:

sergey@server2:~$ curl 10.0.2.8:88
curl: (7) Failed to connect to 10.0.2.8 port 88: connection refused

But if I use port 32319 I get the access:

sergey@server2:~$ curl 10.0.2.8:32319
{"msg":"superuser, Hello from GeoServer"}

Also I can get the access if I am on the machine with Kubernetes:

sergey@server:~$ curl 10.98.241.39:88
{"msg":"superuser, Hello from GeoServer"}

What reasons cause that I can't get the access by EXTERNAL-IP and PORT?

-- sergiusac
docker
kubernetes
networking

2 Answers

5/5/2019

Load Balancer on Kubernetes is a feature that will create a Load Balancer on the Cloud Provider side . So if your kubernetes is not on cloud provider like GCP, AWS or Azzure then it's won't create a real loadbalancer

-- Fauzan
Source: StackOverflow

5/5/2019

Under the hood Load Balancer service is also a NodePort, that's why you can connect to NodeIP:32319. You can read more about NodePort services here: https://kubernetes.io/docs/concepts/services-networking/service/#nodeport

Also you should see that your LoadBalancer External IP is forever in Pending state, which means no real Load Balancer was created. Because you are not running in cloud and there is no provider for Load Balancer. So in your case you can access Load Balancer service only by ClusterIP:88 from Kube nodes or by NodeIP:32319 from outside of Kubernetes cluster.

-- Vasily Angapov
Source: StackOverflow