Last active
April 3, 2016 21:14
-
-
Save johnbuhay/fe0c3205e1d0677b64d5914c0c969cea to your computer and use it in GitHub Desktop.
Further testing confd with json values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
confd: | |
build: . | |
links: | |
- etcd | |
volumes: | |
- ${PWD}/example.tmpl:/etc/confd/templates/example.tmpl | |
environment: | |
- "KEY_PREFIX=haproxy-mynamespace-api" | |
- "ETCD_ENDPOINT=http://etcd:2379" | |
entrypoint: | |
- /go/entrypoint.sh | |
etcdctl: | |
image: local/etcdctl | |
environment: | |
- "ETCDCTL_PEERS=http://etcd:2379" | |
- "SLEEP=30" | |
links: | |
- etcd | |
volumes: | |
- ${PWD}/load.sh:/root/load.sh | |
etcd: | |
image: quay.io/coreos/etcd:v2.0.12 | |
environment: | |
- "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379,http://0.0.0.0:4001" | |
- "ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379,http://etcd:4001" | |
ports: | |
- "4001:4001" | |
- "2379:2379" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo Loading etcd | |
etcdctl set /haproxy-mynamespace-api/services/backends/http-backend-v1-80 '{"claims":["/api"],"name":"http-backend-v1-80","servers":["backend:80"]}' | |
etcdctl set /haproxy-mynamespace-api/services/backends/http-backend-v3-80 '{"claims":["/api/v3"],"name":"http-backend-v3-80","servers":["backend:80"]}' | |
etcdctl set /haproxy-mynamespace-api/services/claims/-api '{"url":"/api","backend":"http-backend-v1-80"}' | |
etcdctl set /haproxy-mynamespace-api/services/claims/-api-v3 '{"url":"/api/v3","backend":"http-backend-v3-80"}' | |
sleep $SLEEP | |
echo Removing backend http-backend-v1-80 | |
etcdctl set /haproxy-mynamespace-api/services/backends/http-backend-v3-80 '{"claims":["/api","/api/v3"],"name":"http-backend-v3-80","servers":["backend:80"]}' | |
etcdctl set /haproxy-mynamespace-api/services/claims/-api '{"url":"/api","backend":"http-backend-v3-80"}' | |
etcdctl set /haproxy-mynamespace-api/services/claims/-api-v3 '{"url":"/api/v3","backend":"http-backend-v3-80"}' | |
etcdctl rm /haproxy-mynamespace-api/services/backends/http-backend-v1-80 | |
sleep $SLEEP | |
echo Test two backends | |
etcdctl set /haproxy-mynamespace-api/services/backends/http-backend-v3-80 '{"claims":["/api","/api/v3"],"name":"http-backend-v3-80","servers":["backend:80","backend:8080"]}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bof | |
# claims, fe stands for frontend | |
frontend http-in | |
bind *:8080 | |
acl site_dead nbsrv(all_servers) lt 1 | |
monitor-uri /u_ok | |
monitor fail if site_dead | |
{{ range (ls "/services/claims" | sortByLength | reverse) }}{{$claim := json (printf "/services/claims/%s" . | getv)}} | |
acl fe-{{$claim.backend}} path_beg -i {{$claim.url}} | |
use_backend {{$claim.backend}}{{.}} if fe-{{$claim.backend}} | |
{{end}} | |
default_backend nomatch | |
# backends | |
{{range $backends := ls "/services/backends"}}{{$backend := json (printf "/services/backends/%s" $backends | getv)}}{{range $c := $backend.claims}} | |
backend {{$backend.name}}{{replace . "/" "-" -1}} | |
balance leastconn | |
option httpchk HEAD {{.}} HTTP/1.1\r\nHost:example.com | |
{{range $backend.servers}} | |
server {{$backend.name}}{{replace $c "/" "-" -1}}-{{join (split . ":") "-"}} {{.}} check | |
{{end}}{{end}}{{end}} | |
backend all_servers | |
option tcp-check {{range $backends := ls "/services/backends"}}{{$backend := json (printf "/services/backends/%s" $backends | getv)}}{{range $c := $backend.claims}}{{range $backend.servers}} | |
server {{$backend.name}}{{replace $c "/" "-" -1}}-{{join (split . ":") "-"}} {{.}} check | |
{{end}}{{end}}{{end}} | |
backend nomatch | |
errorfile 503 /etc/haproxy/errors/nomatch.http | |
# eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment