Coder Social home page Coder Social logo

swarm-barge's Introduction

Docker Swarm Mode on Barge with Vagrant

This shows how to create a Docker Swarm cluster on Barge with Docker Swarm Mode and Vagrant instantly.

It's inspired by DockerCon16 KeyNote and "What's New in Docker" session.

Requirements

Boot up

$ git clone https://github.com/ailispaw/swarm-barge
$ cd swarm-barge
$ make up

That's it.

Tryout

$ ssh -F .ssh_config node-01
Welcome to Barge 2.8.0, Docker version 18.02.0-ce, build fc4de44
[bargee@node-01 ~]$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
h7edyaxyecsgfknmemxfs2nfg *   node-01             Ready               Active              Leader
cq7em3k7l9grtu9qtmpyt0b22     node-02             Ready               Active
wtjh4uh9qao20j96vtdhya0eh     node-03             Ready               Active

Create a service

[bargee@node-01 ~]$ docker service create -d --name vote -p 8080:80 instavote/vote
8rarm6anpwoi2bdgh9epl352j
[bargee@node-01 ~]$ docker service ps vote
ID                  NAME                IMAGE                   NODE                DESIRED STATE       CURRENT STATE          ERROR               PORTS
t2w6e990h9tt        vote.1              instavote/vote:latest   node-01             Running             Running 1 second ago
[bargee@node-01 ~]$  docker ps -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS               NAMES
f6e6009dbac9        instavote/vote:latest   "gunicorn app:app ..."   17 seconds ago      Up 16 seconds       80/tcp              vote.1.t2w6e990h9tt8bwe7syy4m9pj
$ open http://192.168.65.101:8080/

Cats vs Dogs!

Update the service

[bargee@node-01 ~]$ docker service scale vote=3
vote scaled to 3
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service converged
[bargee@node-01 ~]$ docker service ps vote
ID                  NAME                IMAGE                   NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
t2w6e990h9tt        vote.1              instavote/vote:latest   node-01             Running             Running about a minute ago
7ikfah5ba5gt        vote.2              instavote/vote:latest   node-02             Running             Running 20 seconds ago
sc2c5lnlkezf        vote.3              instavote/vote:latest   node-03             Running             Running 21 seconds ago

Check load balancing

[bargee@node-01 ~]$ sudo pkg install iproute2
[bargee@node-01 ~]$ sudo pkg install ipvsadm
[bargee@node-01 ~]$ sudo ls -l /var/run/docker/netns
total 0
-r--r--r--    1 root     root             0 Oct 18 18:26 1-94du9n58gw
-r--r--r--    1 root     root             0 Oct 18 18:27 b973053ec9b7
-r--r--r--    1 root     root             0 Oct 18 18:26 ingress_sbox
[bargee@node-01 ~]$ sudo mkdir -p /var/run/netns
[bargee@node-01 ~]$ sudo ln -s /var/run/docker/netns/ingress_sbox /var/run/netns/lbingress
[bargee@node-01 ~]$ sudo ip netns exec lbingress ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
FWM  256 rr
  -> 10.255.0.6:0                 Masq    1      0          2
  -> 10.255.0.7:0                 Masq    1      0          0
  -> 10.255.0.8:0                 Masq    1      0          0
$ open http://192.168.65.101:8080/

You will see 3 container ID at the bottom of the page on each reloading.

And the following as well.

$ open http://192.168.65.102:8080/
$ open http://192.168.65.103:8080/

Drain a node

[bargee@node-01 ~]$ docker node update --availability=drain node-03
node-03
[bargee@node-01 ~]$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
h7edyaxyecsgfknmemxfs2nfg *   node-01             Ready               Active              Leader
cq7em3k7l9grtu9qtmpyt0b22     node-02             Ready               Active
wtjh4uh9qao20j96vtdhya0eh     node-03             Ready               Drain
[bargee@node-01 ~]$ docker service ps vote
ID                  NAME                IMAGE                   NODE                DESIRED STATE       CURRENT STATE             ERROR               PORTS
t2w6e990h9tt        vote.1              instavote/vote:latest   node-01             Running             Running 3 minutes ago
7ikfah5ba5gt        vote.2              instavote/vote:latest   node-02             Running             Running 2 minutes ago
le7ocmmwplwr        vote.3              instavote/vote:latest   node-02             Running             Running 18 seconds ago
sc2c5lnlkezf         \_ vote.3          instavote/vote:latest   node-03             Shutdown            Shutdown 18 seconds ago

Remove the service

[bargee@node-01 ~]$ docker service rm vote
vote
[bargee@node-01 ~]$ docker service ps vote
no such services: vote
[bargee@node-01 ~]$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
[bargee@node-01 ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

swarm-barge's People

Contributors

ailispaw avatar

Stargazers

 avatar  avatar

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.