kubernetes- load balancer external endpoint is always localhost

2.2k views Asked by At

I was using minikube, and when I created a load balancer it would always give me a diferent ip in the external endpoint, and I was able to access my app.

But now, I changed to docker kubernetes, and when I create a load balancer, it always add the localhost:8181 at the external endpoints.

here is my yaml:

apiVersion: v1
kind: Service
metadata:
  name: app1
  labels:
    app: app1
spec:
  #externalIPs:
  #  - 172.29.0.0
  ports:
  - protocol: TCP
    name: http
    port: 8181
    targetPort: 8181
  type: LoadBalancer
  selector:
    app: app1

its the same as : kubectl expose deployment app1 --port=8181 --target-port=8181 --name=app1 --type=LoadBalancer

as you can see, I tried to add externalIPs, when I do that, both localhost and the externalIP appear in the dashboard, but using the externalIP doesn't work...

I would like it to generate an ip when I create a loadbalancer so I can access my app from there, like I did with minikube.

thanks for your time.

1

There are 1 answers

1
Nick On BEST ANSWER

Official documentation says that:

Type values and their behaviors are: LoadBalancer: Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.

that is why with Kubernetes you have to have a cloud provider enabled (otherwise no External IP would be provisioned):

$ kubectl get svc
NAME                     TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
app1                     LoadBalancer   10.0.2.46     <pending>     8181:30257/TCP   18s

While in minikube it is provisioned for you with the minikube service <service_name>:

$ kubectl get svc
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
app1         LoadBalancer   10.103.51.13   <pending>     8181:30129/TCP   68s

$ minikube service app1
|-----------|------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT |             URL             |
|-----------|------|-------------|-----------------------------|
| default   | app1 | http/8181   | http://192.168.99.100:30129 |
|-----------|------|-------------|-----------------------------|

I would like it to generate an ip when I create a loadbalancer so I can access my app from there, like I did with minikube.

There is awesome post by Ales Nosek on topic.

In short:

In order to be able to create a service of type LoadBalancer, a cloud provider has to be enabled in the configuration of the Kubernetes cluster. As of version 1.6, Kubernetes can provision load balancers on AWS, Azure, CloudStack, GCE and OpenStack.

It highly depends on what you'd like to achieve, but I believe that you may be interested in Ingress.