Skip to content

Latest commit

 

History

History
 
 

swarm

InfraKit Flavor Plugin - Swarm

A reference implementation of a Flavor Plugin that creates a Docker cluster in Swarm Mode.

Schema

Here's a skeleton of this Plugin's schema:

{
  "Type": "",
  "Attachments": {},
  "DockerRestartCommand": ""
}

The supported fields are:

  • Type: The Swarm mode node type, manager or worker
  • Attachments: A mapping from logical IDs to arrays of attachment IDs to associate. The instance plugin being used defines the meaning of attachments and how to attach them.
  • DockerRestartCommand: A shell command that will restart the Docker daemon, used when adding daemon labels

Example

Begin by building plugin binaries.

Security

Since Swarm Mode uses join-tokens to authorize nodes, initializing the Swarm requires:

a. exposing the Docker remote API for the InfraKit plugin to access join tokens b. running InfraKit on the manager nodes to access join tokens via the Docker socket

We recommend approach (b) for anything but demonstration purposes unless the Docker daemon socket is secured. For simplicity, this example does not secure Docker socket.

Running

Start required plugins:

$ build/infrakit-group-default
$ build/infrakit-flavor-vanilla
$ build/infrakit-instance-vagrant
$ build/infrakit-flavor-swarm --host tcp://192.168.2.200:4243

Note that the Swarm Plugin is configured with a Docker host. This is used to determine where the join tokens are fetched from. In this case, we are pointing at the yet-to-be-created Swarm manager node.

Next, create the manager node and initialize the cluster:

$ build/infrakit group commit example/flavor/swarm/swarm-vagrant-manager.json

Once the first node has been successfully created, confirm that the Swarm was initialized:

$ docker -H tcp://192.168.2.200:4243 node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
exid5ftbv15pgqkfzastnpw9n *  infrakit  Ready   Active        Leader

Now the worker group may be created:

$ build/infrakit group commit example/flavor/swarm/swarm-vagrant-workers.json

Once completed, the cluster contains two nodes:

$ docker -H tcp://192.168.2.200:4243 node ls
ID                           HOSTNAME   STATUS  AVAILABILITY  MANAGER STATUS
39hrnf71gzjve3slg51i6mjs4    localhost  Ready   Active
exid5ftbv15pgqkfzastnpw9n *  infrakit   Ready   Active        Leader

Finally, clean up the resources:

$ build/infrakit group destroy swarm-workers

$ build/infrakit group destroy swarm-managers