Coder Social home page Coder Social logo

petrenkotino / haproxy-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colinmollenhour/haproxy-service

1.0 1.0 0.0 18 KB

A Docker container for HAProxy with auto-updating config based on DNS resolution (Docker Swarm, Kontena, etc).

Home Page: https://hub.docker.com/r/colinmollenhour/haproxy-service/

Shell 100.00%

haproxy-service's Introduction

HAProxy Service Load Balancer

This container updates an HAProxy config template periodically using the results of DNS resolution to trigger the update and apply the template and reload HAProxy.

Usage

You can either run this container directly by mounting a template file at /etc/haproxy.cfg.tpl or by copying and baking the template file in using a new Dockerfile. Either way it requires an environment variable SERVICE_HOSTNAME which is the DNS name to resolve when updating the template. Multiple DNS hostnames may be specified separated by commas.

Logging

Rsyslog is installed in order to provide syslog messages from haproxy on stdout. It can be disabled by setting the RSYSLOG environment variable to n. In order to use it your HAProxy config should look like something like this:

global
  log 127.0.0.1 local0 notice

defaults
  log global

Examples

Run directly:

$ docker run \
  -e SERVICE_HOSTNAME=tasks.galera \
  -e UPDATE_FREQUENCY=10 \
  -v /foo/galera-haproxy.cfg.tpl:/etc/haproxy.cfg.tpl \
  colinmollenhour/haproxy-service

Or as a new image:

FROM colinmollenhour/haproxy-service
COPY galera-haproxy.cfg.tpl /etc/haproxy.cfg.tpl
ENV SERVICE_HOSTNAME tasks.galera
ENV UPDATE_FREQUENCY 10

Template Format

Any block of text between the markers {{HOSTS}} and {{/HOSTS}} (must be on separate lines) will be rendered in-place for each IP resolved by the SERVICE_HOSTNAME. The variables $ip and $num (the last octet of the $ip) will be replaced accordingly. The IP addresses will always be sorted in the same order. There may be multiple {{HOSTS}} ... {{/HOSTS}} blocks in the same template file.

Example:

default-server inter 1s
{{HOSTS}}
server node${num} ${ip}:3306 check
{{/HOSTS}}

If the SERVICE_HOSTNAME resolves to 10.0.0.12 and 10.0.0.20 it would render:

default-server inter 1s
server node12 10.0.0.12:3306 check
server node20 10.0.0.20:3306 check

Init Scripts

If you need to run some basic scripts on init before the first template render mount or add a file at /docker-entrypoint-init.sh which will be sourced by docker-entrypoint.sh once on startup.

haproxy-service's People

Contributors

colinmollenhour avatar mattdavenport avatar

Stargazers

Roman avatar

Watchers

James Cloos 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.