sunnuntai 6. maaliskuuta 2016

Simple Go balancer for Kubernetes Raspberry Pi cluster

I made a really simple load balancer/proxy in front of Kubernetes to share traffic between Raspberry Pi's. There are many of these available and a lot better ones too, but I wanted to try out myself what is required to make a load balancer. Previous post was about setting up the cluster.

The load balancer has only two methods, one for socket.io and one for everything else.

http.HandleFunc("/socket.io/", websocketProxy)
http.HandleFunc("/", proxy)

Optimally there would only be one method to handle both, but Socket.io with websocket upgrades needs something more. Also I would have liked to log more about Socket.io traffic, but don't know how (Is it even possible?).

Sharing traffic between addresses is done randomly

func random(min, max int) int {
  return rand.Intn(max-min) + min
}
and usage:
urls[random(0, 3)]

It's in use now, but far from ready. First of all, I'd like to get the addresses from Kubernetes automatically. For now, it's relying on an environment variable:

export BALANCED_URLS=http://[192.168.0.21]:1300,http://[192.168.0.22]:1300,http://[192.168.0.23]:1300

Secondly if and when one of the endpoints is down, balancer should not try to use that endpoint at all. I also don't have any idea how much traffic it will handle, that would be nice to know :)

Github: https://github.com/jelinden/go-loadbalancer

Ei kommentteja:

Lähetä kommentti

Huomaa: vain tämän blogin jäsen voi lisätä kommentin.