Giter Club home page Giter Club logo

haproxy-consul-template's Introduction

haproxy-consul-template

HAProxy with configuration file generated by consul-template for automatically update nodes in Consul KV and reload HAProxy when the KV changes.

Quick start

  • Run a Consul instance (server/agent) on current machine
  • Run this Docker container:
$ docker run -d --net=host -p 80:80 --name=haproxy gnhuy91/haproxy-consul-template
  • Start some test services, note the rest tag - it makes Registrator add the tag to Consul (and SERVICE_CHECK_* env vars for registering health checks to Consul):
# This will create 3 containers
$ for i in $(seq 1 3); do \
  docker run -d -P \
  -e SERVICE_TAGS=rest \
  -e SERVICE_CHECK_HTTP=/ \
  -e SERVICE_CHECK_INTERVAL=5s \
  -e SERVICE_CHECK_TIMEOUT=1s \
  --name=node$i -h=node$i \
  jlordiales/python-micro-service:latest \
  ; done
  • In another terminal, try calling the services via HAProxy:
$ while true; do curl <HAProxy IP>:80/python-micro-service/; echo -----; sleep 1; done;

You can stop and start those test services (docker stop node1) on a new terminal and see the output of above curl changes accordingly.

Bonus

curl localhost:8500/v1/health/checks/python-micro-service | jq . for health checks status.

References

haproxy-consul-template's People

Contributors

huygn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.