Kubernetes LoadBalancer Service not loadbalancing requests

9/20/2019

I have a simple microservice setup running in a minikube cluster. It is inspired by this example. My setup includes a simple router microservice that contains a golang webserver. What I want to test now is the loadbalancing when there is more then one pod. But there seems to be no load-balancing whatsoever.

The kubernetes file for the microservices looks like this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: router
  labels:
    app: router
    tier: router
spec:
  replicas: 2
  strategy: {}
  template:
    metadata:
      labels:
        app: router
        tier: router
    spec:
      containers:
      - image: {myregistry}/router
        name: router
        resources: {}
        ports:
          - name: target-port
            containerPort: 8082
        env:
          - name: PORT
            value: "8082"
status: {}
---
apiVersion: v1
kind: Service
metadata:
  name: router
  labels:
    app: router
    tier: router
spec:
  type: LoadBalancer
  selector:
    app: router
    tier: router
  ports:
  - port: 8082
    name: http
    targetPort: target-port

The skaffold config looks like this:

apiVersion: skaffold/v1beta2
kind: Config
build:
  artifacts:
  - image: {myregistry}/router
    context: src/router/bin
  tagPolicy:
    gitCommit: {}
  local:
    push: false
deploy:
  kubectl:
    manifests:
    - ./kubernetes/**.yaml

Kubernetes correctly deploys two pods. The output of kubectl get pods looks like this:

NAME                           READY   STATUS    RESTARTS   AGE
router-7f75f6f9df-c8mgp        1/1     Running   0          14m
router-7f75f6f9df-k248m        1/1     Running   0          14m

From the skaffold dev log output I can see that every request is routed to the router-7f75f6f9df-c8mgp pod. Even with different browsers all requests end up at the exact same pod.

When I delete this pod there is even a slight downtime of the router microservice even though there is another pod running.

What could be the problem of this behavior?

-- jrenk
kubernetes
load-balancing
minikube
skaffold

1 Answer

9/20/2019

minikube doesn't 'properly' support the LoadBalancer service type. It used to be commonplace to just use the NodePort or externalIP service type instead, however the official hello-minikube sample now states:

On cloud providers that support load balancers, an external IP address would be provisioned to access the Service. On Minikube, the LoadBalancer type makes the Service accessible through the minikube service command

So effectively you should be able to use your minikube LoadBalancer service with: minikube service router

However there is a neat solution that was developed for bare-metal kubernetes clusters called metallb that may be able to help you test this in a better way on minikube.

You can install and configure it on minikube. E.g.

kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.1/manifests/metallb.yaml

Here are some blog posts where others have explained the setup and use of metallb with minikube for LoadBalancer support:

Blog Post 1 Blog Post 2

Here are the official docs.

Hope that helps!

-- Shogan
Source: StackOverflow