Kubernetes (docker-desktop) with multiple LoadBalancer services

12/19/2019

Is it true that I cannot have two LoadBalancer services on a docker-desktop cluster (osx), because they would both use localhost (and all ports are forwarded)?

I created an example and the latter service is never assigned an external IP address but stays in state pending. However, the former is accessible on localhost.

> kubectl get all     
NAME                                       READY   STATUS    RESTARTS   AGE
pod/whoami-deployment-9f9c86c4f-l5lkj      1/1     Running   0          28s
pod/whoareyou-deployment-b896ddb9c-lncdm   1/1     Running   0          27s
pod/whoareyou-deployment-b896ddb9c-s72sc   1/1     Running   0          27s

NAME                        TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/kubernetes          ClusterIP      10.96.0.1       <none>        443/TCP        95s
service/whoami-service      LoadBalancer   10.97.171.139   localhost     80:30024/TCP   27s
service/whoareyou-service   LoadBalancer   10.97.171.204   <pending>     80:32083/TCP   27s

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/whoami-deployment      1/1     1            1           28s
deployment.apps/whoareyou-deployment   2/2     2            2           27s

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/whoami-deployment-9f9c86c4f      1         1         1       28s
replicaset.apps/whoareyou-deployment-b896ddb9c   2         2         2       27s

Detailed state fo whoareyou-service:

kubectl describe service whoareyou-service
Name:                     whoareyou-service
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"whoareyou-service","namespace":"default"},"spec":{"ports":[{"name...
Selector:                 app=whoareyou
Type:                     LoadBalancer
IP:                       10.106.5.8
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  30333/TCP
Endpoints:                10.1.0.209:80,10.1.0.210:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
-- Daniel
docker
docker-desktop
kubernetes

1 Answer

1/20/2020

I decided to copy my comments, as they partially explain the problem, and make a Community Wiki answer out of them so it is more clearly seen and available for possible further edits by the Community:

It works probably exactly the same way as in Minikube. As docker-desktop is unable to provision real LoadBalancer it can still "simulate" creating Service of such type using NodePort (this can easily be seen from port range it uses). I'm pretty sure you cannot use same IP address as the ExternalIP of the LoadBalancer Service and if you create one more Service of such type, your docker-desktop has no other choice than to use your localhost one more time. As it is already used by one Service it cannot be used by another one and that's why it remains in a pending state.

Note that if you create real LoadBalancer in a cloud environment, each time new IP is provisioned and there is no situation that next LoadBalancer you create gets the same IP that is already used by the existing one. Apparently here it cannot use any other IP then one of localhost, and this one is already in use. Anyway I would recommend you to simply use NodePort if you want to expose your Deployment to the external world.

-- mario
Source: StackOverflow