Skip to content

Instantly share code, notes, and snippets.

@MerNat
Forked from zaherg/readme.md
Created July 20, 2020 11:21
Show Gist options
  • Save MerNat/e3f30f99a672df5253220783aa970a81 to your computer and use it in GitHub Desktop.
Save MerNat/e3f30f99a672df5253220783aa970a81 to your computer and use it in GitHub Desktop.

RethinkBD cluster with Traefik & Docker Swarm

The main key is to create two network interfaces, one will be used with traefik and the other one will be used for the containers to communicate with each other

In the yml file I called them application and traefik, then you need to tell Traefik via the labels to use one of them.

When you deploy a stack you will have a name for it, which is also used as a prefix for the netwroks .. etc, to make it simple we will use the environment variables, so that we can have a flixable yml file.

  1. First export the project name, change my-project to whatever you like.
export PROJECT_NAME=my-project
  1. Deploy your stack
docker stack deploy -c old_working.yml --prune $PROJECT_NAME
  1. If you are not running ARM64 device, you need to use the official RethinkDB docker image as my image zaherg/rethinkdb:2.3.6 was built for ARM64 devices specifically.

  2. Add docker.pi and rethinkdb.docker.pi to your /etc/hosts file so you can access them locally.


THE INSTRUCTIONS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

version: "3.7"
services:
reverse-proxy:
image: traefik:v2.2
command:
- "--accesslog=true"
- "--log=true"
- "--log.level=debug"
- "--api.insecure=true"
- "--api.dashboard=true"
- "--providers.docker"
- "--providers.docker.watch=true"
- "--providers.docker.swarmMode=true"
- "--providers.docker.swarmModeRefreshSeconds=60s"
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--entryPoints.rethinkdb-port.address=:28015"
- "--entryPoints.rethinkdb-port-cluster.address=:29015"
- "--serversTransport.insecureSkipVerify=true"
ports:
- "80:80"
- "8080:8080"
- "443:443"
- "28015:28015"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /etc/localtime:/etc/localtime:ro
networks:
- traefik
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.service=api@internal"
- "traefik.http.routers.api.rule=Host(`docker.pi`)"
- "traefik.http.routers.api.middlewares=proxy-compress"
- "traefik.http.middlewares.api-compress.compress=true"
- "traefik.http.services.api.loadbalancer.server.url=http://proxy"
- "traefik.http.services.proxy.loadbalancer.server.port=8080"
mode: global
placement:
constraints:
- node.role == manager
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: any
rethinkdb:
hostname: rethinkdb
image: zaherg/rethinkdb:2.3.6 # use this image if you are running ARM64 device, otherwise use the official one
command: rethinkdb --bind all --canonical-address rethinkdb -j rethinkdb:29015
volumes:
- type: bind
source: /mnt/data/rethinkdb
target: /data
stop_grace_period: 1m30s
networks:
- application
- traefik
deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=${PROJECT_NAME}_traefik"
- "traefik.http.middlewares.rethinkdb-compress.compress=true"
- "traefik.http.routers.rethinkdb.middlewares=rethinkdb-compress"
- "traefik.http.routers.rethinkdb.entrypoints=web"
- "traefik.http.routers.rethinkdb.rule=Host(`rethinkdb.docker.pi`)"
- "traefik.http.services.rethinkdb.loadbalancer.server.port=8080"
- "traefik.tcp.routers.rethinkdb.service=rethinkdb"
- "traefik.tcp.routers.rethinkdb.entrypoints=rethinkdb-port"
- "traefik.tcp.routers.rethinkdb.rule=HostSNI(`*`)"
- "traefik.tcp.services.rethinkdb.loadbalancer.server.port=28015"
- "traefik.tcp.routers.rethinkdb-cluster.service=rethinkdb-cluster"
- "traefik.tcp.routers.rethinkdb-cluster.entrypoints=rethinkdb-port-cluster"
- "traefik.tcp.routers.rethinkdb-cluster.rule=HostSNI(`*`)"
- "traefik.tcp.services.rethinkdb-cluster.loadbalancer.server.port=29015"
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: any
delay: 10s
max_attempts: 10
window: 120s
rethinkdb-replica:
image: zaherg/rethinkdb:2.3.6 # use this image if you are running ARM64 device, otherwise use the official one
command: rethinkdb --bind all -j rethinkdb:29015
stop_grace_period: 1m30s
networks:
- application
- traefik
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=${PROJECT_NAME}_traefik
- traefik.tcp.routers.rethinkdb-replica.service=rethinkdb-replica
- traefik.tcp.routers.rethinkdb-replica.entrypoints=rethinkdb-port-cluster
- traefik.tcp.routers.rethinkdb-replica.rule=HostSNI(`*`)
- traefik.tcp.services.rethinkdb-replica.loadbalancer.server.port=29015
replicas: 3
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: any
delay: 10s
max_attempts: 10
window: 120s
networks:
application:
traefik:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment