HAProxy with ETCD for REST
Jochen Mader <jochen.mader@codecentric.de> v0.1, October 2015: Initial version.
== Introduction
HAProxy is a feature rich, easy to configure reverse proxy.
ETCD is the distributed hierarchical key/value-store from the CoreOS-project.
This project provides some shell infrastructure to make HAProxy pull lists of hosts and their associated HTTP-URLs from ETCD.
== Purpose
This project is geared towards being used for experimenting with microservices. It gives some ideas on how to do this in production but it’s aim is to be usable on a local machine without too much effort.
== How it works
Let’s say we want to map the following URLs:
/browse
/detail
/checkout
Create a directory for each one in ETCD. Usin cURl you could do the following to create the checkout-service and add a host.
curl -L http://<etcdhost>/v2/keys/checkout -XPUT -d dir=true curl -L http://<etcdhost>/v2/keys/checkout/<nodename> -XPUT -d value="<host:port>"&ttl=15
-
<etcdhost>: Host of your ETCD-instance
-
<nodename>: A name for your node for easier debugging
-
<host:port>: Host and port under which the URL resides. In this case the service should be reachable as http://<host:port>/checkout
== Starting it
Get ETCD installed. Being an Apple user I use Homebrew for this:
brew install etcd
Start watching
etcdctl exec-watch --recursive / -- ./build_cfg_and_reload.sh