Skip to content

Docker Swarm

Lyes S edited this page Sep 28, 2021 · 11 revisions

Table Of Contents

Objective

VMs Configuration

Swarm Cluster Configuration

Initialization

Manager Node

docker swarm init --advertise-addr 192.168.1.4

Mitsuke

Join

Worker Node(s)

docker swarm join --token SWMTKN-1-3387hh4sl1c57tjbxy92ez2xikoda47z30io49clll38rvpl5h-e5eskq38p877fe45cc15vyfgf 192.168.1.4:2377

IceTea

Covid

Verification

$ docker node ls

ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
24h4c7tto9zwevgr1pwulchxd     covid      Ready     Active                          20.10.8
lynuv8m3ek02wagogfpcewyy2     ice-tea    Ready     Active                          20.10.8
yup25xu11jmizujl0sg1rpw68 *   mitsuke    Ready     Active         Leader           20.10.8

Deployment

Docker Hub Repositories

Environment Variables and Secrets

Environment Variables

export SPRING_ACTIVEMQ_BROKER_URL=tcp://apache-activemq:61616 \
export SPRING_JMS_LISTENER_AUTO_STARTUP=true \
export SPRING_CLOUD_CONSUL_ENABLED=true \
export SPRING_CLOUD_GATEWAY_DISCOVERY_LOCATOR_ENABLED=true \
export SPRING_CLOUD_CONSUL_HOST=http://hashicorp-consul \
export SPRING_CLOUD_CONSUL_PORT=8500 \
export SPRING_ZIPKIN_ENABLED=true \
export SPRING_ZIPKIN_BASE_URL=http://openzipkin-zipkin:9411

Secrets Creation

echo "admin" | docker secret create activemq_user -
echo "admin" | docker secret create activemq_password -

Stack Deployment

$ docker stack deploy -c docker-stack.yml stack

Creating network stack_miniSwarm
Creating service stack_apache-activemq
Creating service stack_hashicorp-consul
Creating service stack_gateway-service
Creating service stack_publisher-service
Creating service stack_subscriber-service
Creating service stack_visualizer
Creating service stack_openzipkin-zipkin
$ docker stack ps stack
ID             NAME                         IMAGE                                NODE      DESIRED STATE   CURRENT STATE            ERROR     PORTS
yuxux1tcq2js   stack_apache-activemq.1      lsefiane/activemq:5.16.2-alpine      covid     Running         Running 9 minutes ago
c86hnp165zwh   stack_gateway-service.1      lsefiane/gateway-service:latest      covid     Running         Running 9 minutes ago
r1q3a6dxycz2   stack_hashicorp-consul.1     consul:latest                        mitsuke   Running         Running 11 minutes ago
7gx3zdvlf6gb   stack_openzipkin-zipkin.1    openzipkin/zipkin:latest             mitsuke   Running         Running 10 minutes ago
r18gbm1ikjm8   stack_publisher-service.1    lsefiane/publisher-service:latest    covid     Running         Running 8 minutes ago
uzdvv4gkjy6o   stack_publisher-service.2    lsefiane/publisher-service:latest    ice-tea   Running         Running 9 minutes ago
bk2ieyqobs56   stack_subscriber-service.1   lsefiane/subscriber-service:latest   ice-tea   Running         Running 9 minutes ago
7eno2x2s2dgz   stack_subscriber-service.2   lsefiane/subscriber-service:latest   covid     Running         Running 8 minutes ago
xepfy6595qcj   stack_subscriber-service.3   lsefiane/subscriber-service:latest   ice-tea   Running         Running 9 minutes ago
h7gjkc1hbvpk   stack_visualizer.1           bretfisher/visualizer:latest         mitsuke   Running         Running 11 minutes ago

POST Request

 curl -X POST -H "Content-Type: application/json" \
    -d '{"description": "description sample...."}' \
    192.168.1.4:8080/publisher/publish/virtual-topic
{"id":"16f929d6-d3ba-4368-bad9-1c1c4f0a2f37","timestamp":"12-09-2021 17:55:45","description":"description sample...."}

Docker Swarm Visualization

http://192.168.1.4:5000/