GithubHelp home page GithubHelp logo

hankerepo / consul-swarm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sdelrio/consul

0.0 3.0 0.0 17 KB

docker consul for use in swarm mode

License: Apache License 2.0

Shell 66.78% Dockerfile 21.25% HCL 11.98%

consul-swarm's Introduction

Consul with the Autopilot Pattern

Consul in Docker, designed to be self-operating according to the autopilot pattern. This application demonstrates support for configuring the Consul raft so it can be used as a highly-available discovery catalog for other applications using the Autopilot pattern.

DockerPulls DockerStars

Run consul in a virtualbox swarm cluster

  1. If you don't have it, install the Docker for Windows, docker for Mac, or Docker Toolbox(including docker and docker-compose) on your laptop or other environment.
  2. Create a swarm mode cluster

The option --engine-opt experimental is not mandatory but on docker v1.13 you can run docker service logs consul, to view the logs from all the cluster service.

for i in 1 2 3; do
    docker-machine create -d virtualbox --engine-opt experimental swarm-$i
done

eval $(docker-machine env swarm-1)

docker swarm init --advertise-addr $(docker-machine ip swarm-1)

TOKEN=$(docker swarm join-token -q manager)

for i in 2 3; do
  eval $(docker-machine env swarm-$i)
  docker swarm join --token $TOKEN --advertise-addr $(docker-machine ip swarm-$i) $(docker-machine ip swarm-1):2377
done

  1. Create a network for consul
docker network create consul-net -d overlay --subnet=172.20.0.0/24

The option --subnet is not mandatory, is just I want to be on different network that the usually 10.x.x.x that docker assign by default.

  1. Create a service for the swarm

1.1 Using docker-compose v1.10+

docker deploy -c docker-compose.yml consul

1.2 Manually creating the service

docker service create --network=consul-net --name=consul \
    -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' \
    -e CONSUL_BIND_INTERFACE='eth0' \
    -e CONSUL=consul \
    -e CONSUL_CHECK_LEADER=true \
    --replicas 3 \
    --update-delay 10s \
    --update-parallelism 1 \
    -p 8500:8500 sdelrio/consul

Environment vars

The image use the official consul as base image, so all environment vars can be used (like CONSUL_LOCAL_CONFIG, CONSUL_BIND_INTERFACE).

  • CONSUL: Name of the service to ask for other consul peers. The image will use docker DNS to find the other peers. Usually this will be the name of the swarm service.
  • CONSUL_CHECK_LEADER: If is true the logs will show each health check interval if the container is the leader and or container's IP and the leader's IP:
consul_consul.3.l0e0zr114x50@swarm-1    | 2017/01/26 00:11:22     [CP] I'm leader (172.20.0.6)
consul_consul.2.qwx39safki82@swarm-2    | 2017/01/26 00:11:26     [CP] Leader is 172.20.0.6, I'm 172.20.0.3
consul_consul.4.qws5isxw6gpm@swarm-3    | 2017/01/26 00:11:27     [CP] Leader is 172.20.0.6, I'm 172.20.0.4
consul_consul.3.l0e0zr114x50@swarm-1    | 2017/01/26 00:11:32     [CP] I'm leader (172.20.0.6)
consul_consul.2.qwx39safki82@swarm-2    | 2017/01/26 00:11:36     [CP] Leader is 172.20.0.6, I'm 172.20.0.3
consul_consul.4.qws5isxw6gpm@swarm-3    | 2017/01/26 00:11:37     [CP] Leader is 172.20.0.6, I'm 172.20.0.4
consul_consul.3.l0e0zr114x50@swarm-1    | 2017/01/26 00:11:42     [CP] I'm leader (172.20.0.6)

Docker Entry Point

The entrypoint will execute consul with containerpilot, you can use the command to set your own parameters, by default the command will need 3 replicas:

agent -server -bootstrap-expect 3 -ui -client=0.0.0.0 -retry-interval 5s --log-level warn -disable-host-node-id

Consul generates node IDs from hostname and my conflict when you run two or more consul containers on the same host. Consul (v0.8.1+) has -disable-host-node-id flag to avoid this issue.

References

consul-swarm's People

Watchers

 avatar  avatar  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.