Skip to content

Instantly share code, notes, and snippets.

@devopstoday11
Forked from errordeveloper/Swarm.md
Created November 13, 2020 20:02
Show Gist options
  • Save devopstoday11/04a2bc65b82c7f122fc3925b19a7fa55 to your computer and use it in GitHub Desktop.
Save devopstoday11/04a2bc65b82c7f122fc3925b19a7fa55 to your computer and use it in GitHub Desktop.

Revisions

  1. @errordeveloper errordeveloper revised this gist Jan 21, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Swarm.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Weave Net and Docker Swarm

    This example show how-to setup a very simple Swarm cluster with Weave Net.
    This example show how-to setup a very simple Swarm cluster enabled with Weave Net.

    ## Infratructure

  2. @errordeveloper errordeveloper created this gist Jan 21, 2016.
    110 changes: 110 additions & 0 deletions Swarm.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,110 @@
    # Weave Net and Docker Swarm

    This example show how-to setup a very simple Swarm cluster with Weave Net.

    ## Infratructure

    There are two hosts that have a recent version of Docker Engine running.

    These hosts are named `host1` and `host2`, and might have the following in
    `/etc/hosts` or you just substitute IP addresses in the commands shown below.


    ```
    192.168.131.139 host1
    192.168.131.140 host2
    ```

    ## Install and launch Weave Net

    To install Weave Net run the following commands on each of the hosts
    ```
    sudo curl --silent --location git.io/weave --output /usr/local/bin/weave
    chmod +x /usr/local/bin/weave
    ```

    Now start the router on each of the host with
    ```
    weave luanch-router host1 host2
    ```

    Proxy needs to be launched with the following arguments
    ```
    weave launch-proxy -H 0.0.0.0:12375 --no-detect-tls
    ```

    > You can omit `--no-detect-tls`, but in that case you might wish to omit
    > all of the arugments. If so, you will need to ensure that TLS keys are
    > in all the right places.
    ## Launch Swarm manger

    Swarm manager can run very simply like this agains two of the host that
    run Weave Net and the Docker API proxy is listening on port 12375:

    ```
    docker run -d -p 2377:2375 swarm manage nodes://host1:12375,host2:12375
    ```

    > If you would like to use a different discovery mechanism, you can do this
    > but then you will need run Swarm agents on each of the hosts and ensure
    > that those are pointed at the address the proxy is listening on. This
    > would typically mean `swarm join --addr <ip>:12375 <discovery>`.
    ## Ping Me, I am on Weave Net!

    Let's start 20 containers via Swarm, on the same host the manager is running.
    ```
    for i in $(seq 20)
    do docker -H 127.0.0.1:2377 run -td --name="pingme-${i}" --hostname="pingme.weave.local" centos:7
    done
    ```

    Check `weave status dns` and you will see there are 20 entries now. You can also
    do a lookup with `weave dns-lookup pingme` a few times and see that shuffled IPs
    are being returned each time.

    Next, let's run the ping test like this:
    ```
    $ docker -H 127.0.0.1:2377 run -ti centos:7
    [root@4a73489ae22e /]# ping -c1 pingme
    PING pingme.weave.local (10.40.0.5) 56(84) bytes of data.
    64 bytes from pingme.weave.local (10.40.0.5): icmp_seq=1 ttl=64 time=1.12 ms
    --- pingme.weave.local ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 1.128/1.128/1.128/0.000 ms
    [root@4a73489ae22e /]# ping -c1 pingme
    PING pingme.weave.local (10.40.0.2) 56(84) bytes of data.
    64 bytes from pingme.weave.local (10.40.0.2): icmp_seq=1 ttl=64 time=9.34 ms
    --- pingme.weave.local ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 9.345/9.345/9.345/0.000 ms
    [root@4a73489ae22e /]# ping -c1 pingme
    PING pingme.weave.local (10.32.0.1) 56(84) bytes of data.
    64 bytes from pingme.weave.local (10.32.0.1): icmp_seq=1 ttl=64 time=0.166 ms
    --- pingme.weave.local ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.166/0.166/0.166/0.000 ms
    [root@4a73489ae22e /]# ping -c1 pingme
    PING pingme.weave.local (10.32.0.8) 56(84) bytes of data.
    64 bytes from pingme.weave.local (10.32.0.8): icmp_seq=1 ttl=64 time=0.162 ms
    --- pingme.weave.local ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.162/0.162/0.162/0.000 ms
    [root@4a73489ae22e /]# ping -c1 pingme
    PING pingme.weave.local (10.40.0.4) 56(84) bytes of data.
    64 bytes from pingme.weave.local (10.40.0.4): icmp_seq=1 ttl=64 time=0.987 ms
    --- pingme.weave.local ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.987/0.987/0.987/0.000 ms
    [root@4a73489ae22e /]# exit
    ```

    Now, just to convince yourself, run `docker -H 127.0.0.1:2377 ps` to check that all
    of these 20 containers are on different hosts.