diff --git a/roles/lxc_swarm/tasks/deploy.yml b/roles/lxc_swarm/tasks/deploy.yml index dacef53..873f345 100644 --- a/roles/lxc_swarm/tasks/deploy.yml +++ b/roles/lxc_swarm/tasks/deploy.yml @@ -10,28 +10,20 @@ - name: Deploy swarm stack deployment file shell: docker stack deploy -c stack.yaml stack +#- pause: +# seconds: 30 + - name: Update swarm stack service "bnode" with proper environmental variables shell: | - unset MASTER_ADDR - mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"` + sleep 60; mcontainer_addr=`ssh root@10.0.3.100 "docker ps|xargs -n1|grep -i NAMES -A 1|tail -1"` MASTER_ADDR=`ssh -t root@10.0.3.100 "docker exec -it $mcontainer_addr ip a s|grep -i 10.0|head -1 2>/dev/null" 2>&1 |grep inet|awk '{print $2}'|cut -d "/" -f 1|tr -d ' '` - [ -z $MASTER_ADDR ] && echo "Node 1 hasn't yet been initialized" && exit 1 + [ -z $MASTER_ADDR ] && echo "Node 1 hasn't yet been initialized" env MASTER_ADDR="${MASTER_ADDR}" docker stack deploy -c stack.yaml stack - env MASTER_ADDR="${MASTER_ADDR}" docker service scale stack_bnode=1 +# env MASTER_ADDR="${MASTER_ADDR}" docker service scale stack_bnode=1 # sleep 30 args: executable: /bin/bash -#- name: Wait for seed container to start -# pause: -# seconds: 30 - -#- name: Start mariadb cluster on node1 -# shell: docker service scale stack_node1=1 - -#- name: Remove seed container -# shell: docker service rm stack_seed - #- name: Wait for nodes[0] container to start # pause: # seconds: 30 diff --git a/roles/lxc_swarm/tasks/swarm.yml b/roles/lxc_swarm/tasks/swarm.yml index f7ae9fd..7818edd 100644 --- a/roles/lxc_swarm/tasks/swarm.yml +++ b/roles/lxc_swarm/tasks/swarm.yml @@ -10,6 +10,11 @@ register: worker_token when: inventory_hostname in groups['manager'] +- name: Create 'mariadb' overlay network + shell: docker network create -d overlay --subnet=10.0.10.0/24 mariadb + ignore_errors: true + when: inventory_hostname in groups['manager'] + - name: Prepare swarm workers docker_swarm: state: join diff --git a/stack.yaml b/stack.yaml index 270922b..fab5be9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,82 +1,73 @@ -version: '3.4' +version: '3.8' services: -# seed: -# image: colinmollenhour/mariadb-galera-swarm -# environment: -# - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password -# - MYSQL_USER=user -# - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password -# - MYSQL_DATABASE=database -# - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password -# - NODE_ADDRESS=^10.0.*.* -# networks: -# - galera_network -# command: seed -# deploy: -# placement: -# # Services must run only on workers with one service per container -# constraints: -# - node.labels.node1 == true -# - node.role == worker -# volumes: -# - /var/lib/mysql:/var/lib/mysql -# secrets: -# - xtrabackup_password -# - mysql_password -# - mysql_root_password anode: image: colinmollenhour/mariadb-galera-swarm -# hostname: environment: - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password - - NODE_ADDRESS=^10.0.*.* + - MYSQL_USER=user + - MYSQL_PASSWORD_FILE=/run/secrets/mysql_password + - MYSQL_DATABASE=database + - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password + - NODE_ADDRESS=^10.0.10.* - HEALTHY_WHILE_BOOTING=1 networks: - - galera_network + - mariadb + ports: + - mode: host + target: 4567 + published: 4567 command: node tasks.anode,tasks.bnode volumes: - /var/lib/mysql:/var/lib/mysql deploy: + resources: + limits: + cpus: '0.75' + memory: 250M + reservations: + cpus: '0.5' + memory: 100M # Replicated mode mode: replicated replicas: 1 -# restart_policy: -# delay: 10s -# max_attempts: 10 -# window: 60s placement: # Services must run only on workers with one service per container - #max_replicas_per_node: 1 + max_replicas_per_node: 1 constraints: - node.labels.node1 == true - node.role == worker secrets: - xtrabackup_password + - mysql_password + - mysql_root_password bnode: image: colinmollenhour/mariadb-galera-swarm - #hostname: bnode environment: - XTRABACKUP_PASSWORD_FILE=/run/secrets/xtrabackup_password - - NODE_ADDRESS=^10.0.*.* + - NODE_ADDRESS=^10.0.10.* - HEALTHY_WHILE_BOOTING=1 - MASTER_ADDR networks: - - galera_network + - mariadb command: node $MASTER_ADDR,tasks.bnode +# command: node tasks.anode,tasks.bnode volumes: - /var/lib/mysql:/var/lib/mysql deploy: + resources: + limits: + cpus: '0.75' + memory: 250M + reservations: + cpus: '0.5' + memory: 100M # Replicated mode mode: replicated - replicas: 0 - # restart_policy: - # delay: 10s - # max_attempts: 10 - # window: 60s + replicas: 1 placement: # Services must run only on workers with one service per container - #max_replicas_per_node: 1 + max_replicas_per_node: 1 constraints: - node.labels.node2 == true - node.role == worker @@ -91,7 +82,9 @@ services: # driver: local networks: - galera_network: + mariadb: + external: + name: mariadb secrets: xtrabackup_password: diff --git a/swarmlab/Makefile b/swarmlab/Makefile deleted file mode 100644 index c983726..0000000 --- a/swarmlab/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -all: preautomation provision swarm_deploy - -preautomation: - /bin/bash ./ansible_install.sh - -provision: - /bin/bash ./ansible_provisioning.sh - -swarm_deploy: - /bin/bash ./ansible_swarm_config.sh - -clean: - /bin/bash ./clean.sh diff --git a/swarmlab/ansible.cfg b/swarmlab/ansible.cfg deleted file mode 100644 index 0a455bc..0000000 --- a/swarmlab/ansible.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[defaults] -#added parameters for actual management of LXC nodes with ansible because of bridged networking packet loss -gather_timeout = 30 -timeout = 45 -host_key_checking = False diff --git a/swarmlab/ansible_install.sh b/swarmlab/ansible_install.sh deleted file mode 100755 index 0d29e62..0000000 --- a/swarmlab/ansible_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -[ `id -u` -ne 0 ] && exit 1 -echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" >> /etc/apt/sources.list -apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 -apt update && apt install -y ansible diff --git a/swarmlab/ansible_provisioning.sh b/swarmlab/ansible_provisioning.sh deleted file mode 100755 index 44c33c0..0000000 --- a/swarmlab/ansible_provisioning.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -[ `id -u` -ne 0 ] && exit 1 -test -f /root/.ssh/id_rsa.pub || ssh-keygen -t rsa -b 4096 -N '' -f /root/.ssh/id_rsa -ansible-playbook -i inventory/hosts --skip-tags swarm --diff -v swarm-galera.yml diff --git a/swarmlab/ansible_swarm_config.sh b/swarmlab/ansible_swarm_config.sh deleted file mode 100755 index c39509c..0000000 --- a/swarmlab/ansible_swarm_config.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -[ `id -u` -ne 0 ] && exit 1 -ansible-playbook -i inventory/hosts --tags swarm --diff -v swarm-galera.yml