Skip to content

Instantly share code, notes, and snippets.

@alombarte
Created June 4, 2020 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alombarte/fa3731dae6003bfae2019ef6a383498b to your computer and use it in GitHub Desktop.
Save alombarte/fa3731dae6003bfae2019ef6a383498b to your computer and use it in GitHub Desktop.
Balance two krakend nodes using HAProxy
version: "3"
services:
balancer:
image: haproxy:1.7
volumes:
- ".//haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
ports:
- "8080:80"
krakend_1:
image: devopsfaith/krakend
# We enable the debug endpoint so krakend offers the /__debug endpoint.
# This option is production-safe (it only answers with a "pong")
command: run -d -c krakend.json
volumes:
- "./:/etc/krakend/"
krakend_2:
image: devopsfaith/krakend
command: run -d -c krakend.json
volumes:
- "./:/etc/krakend/"
# This is not a configuration ready for production!!!
# Just a quick test to balance traffic to 2 krakend nodes
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 100
timeout client 1000
timeout server 1000
frontend api_gateway
bind :80
use_backend nodes
backend nodes
mode http
balance roundrobin
option httpchk GET /health
server krakend_1 krakend_1:8080 check
server krakend_2 krakend_2:8080 check
{
"version": "2",
"endpoints": [
{
"endpoint": "/hello/{user}",
"backend": [
{
"url_pattern": "/users/{user}",
"host": ["https://api.github.com"]
}
]
},
{
"endpoint": "/health",
"extra_config": {
"github.com/devopsfaith/krakend/proxy": {
"static": {
"data": {
"status": "OK"
},
"strategy": "always"
}
}
},
"backend": [
{
"url_pattern": "/__debug",
"host": [
"http://localhost:8080"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment