Provisioning the infrastructure with belt

First, we created a cluster template named swarm2k for DigitalOcean with the following command:

$ belt cluster new --driver digitalocean swarm2k

The preceding command creates a configuration template file in the current directory called .belt/swarm2k/config.yml. This was our starting point to define other attributes.

We checked if our cluster was defined by running the following command:

$ belt cluster ls
CLUSTER       ACTIVE    LEADER    MASTERS    #NODES
swarm2k       -         -         -          0 / 0

With the use command, we can switch and used the available swarm2k clusters, as follows:

$ belt use swarm2k
swarm2k

At this point, we refined the swarm2k template's attributes.

By setting  the DigitalOcean's instance region to be sgp1 by issuing the following command:

$ belt cluster update region=sgp1

Belt required to define all necessary values with this command. Here's a list of the required template keys for the DigitalOcean driver that we specified in config.yml:

  • image: This is to specify the DigitalOcean image ID or snapshot ID
  • region: This is to specify the DigitalOcean region, for example, sgp1 or nyc3
  • ssh_key_fingerprint: This is to specify the DigitalOcean SSH Key ID or fingerprint
  • ssh_user: This is to specify the username used by the image, for example, root
  • access_token: This is to specify DigitalOcean's access token; it is recommended to not put any of the tokens here

Tip

Every template attribute has its environment variable counterpart. For example, the access_token attribute can be set via DIGITALOCEAN_ACCESS_TOKEN. So, in practice, we can also export DIGITALOCEAN_ACCESS_TOKEN as a shell variable before proceeding.

With the configuration in place, we verified the current template attributes by running the following piece of code:

$ belt cluster config
digitalocean:
  image: "123456"
  region: sgp1
  ssh_key_fingerprint: "800000"
  ssh_user: root

Now, we created a set of 3 512MB manger nodes called mg0, mg1, and mg2 with the following syntax:

$ belt create 8192MB mg[0:2]
NAME   IPv4         MEMORY  REGION  IMAGE       STATUS
mg2    128.*.*.11   8192     sgp1   Ubuntu docker-1.12.1 new
mg1    128.*.*.220  8192     sgp1   Ubuntu docker-1.12.1 new
mg0    128.*.*.21   8192     sgp1   Ubuntu docker-1.12.1 new

All new nodes are initialized and go to a new status.

We can use the following command to wait until all 3 nodes become active:

$ belt status --wait active=3
STATUS  #NODES  NAMES
new         3   mg2, mg1, mg0
STATUS  #NODES  NAMES
new         3   mg2, mg1, mg0
STATUS  #NODES  NAMES
new         3   mg2, mg1, mg0
STATUS  #NODES  NAMES
active      3   mg2, mg1, mg0

Then, we set node1 to be the active manger host, and our Swarm will be ready to be formed. Setting the active host can be done by running the active command, as follows:

$ belt active mg0
swarm2k/mg0

At this point, we formed a swarm. We initialized mg0 as the manager leader, as follows:

$ belt docker swarm init --advertise-addr 128.*.*.220
Swarm initialized: current node (24j7sytbomhshtayt74lf7njo) is now 
    a manager.

The preceding command outputs the strings to copy and paste to join other managers and workers, for example, take a look at the following command:

    docker swarm join 
    --token SWMTKN-1-1wwyxnfcgqt...fwzc1in3 
    128.*.*.220:2377

Belt provides a convenient shortcut to join nodes with the following syntax, that was what we used to join mg1 and mg2 to the swarm.:

$ belt --host mg[1:2] docker swarm join 
    --token --token SWMTKN-1-1wwyxnfcgqt...fwzc1in3 
    128.*.*.220:2377

Now, we have the mg0, mg1, and mg2 managers configured and ready to get the swarm of workers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset