/google-cloud-swarm

Scripts to create and manage a Docker Swarm cluster on Google Cloud Platform

Primary LanguageHTMLApache License 2.0Apache-2.0

google-cloud-swarm

Scripts to create and manage a Docker Swarm cluster on Google Cloud Platform.

Prerequisites

Before you start

  • Make sure you create a Google Cloud Project
  • You need to enable Google Cloud Deployment Manager V2 API using this link.
  • Also add server-to-server credentials json file in the keys folder with project name as json file name

    example:
        project name = projectxyz-app
        credentials file should be saved like this
        keys/projectxyz-app.json

Login:

$ gcloud init

Create a Cluster

./swarm-up.sh
Choose the project

By default, this will create a cluster with one manager and two workers. You can edit this and more options in the options.yaml file.

Delete a Cluster

./swarm-down.sh


Choose the project

Resize a Cluster

./swarm-resize.sh <NUM_WORKERS>
Choose the project

Options

Edit the options.yaml file to specify your options.

Cluster Config

  • Cluster Configuration Options
    • prefix = All nodes in the Swarm will start with this Prefix. This allows you to have multiple Swarms in the same project.
    • zone = Google Cloud Zone for the nodes - default: us-central1-f
  • Manager Options
    • manager_machine_type = Google Cloud Machine Type for the Manager nodes - default: n1-standard-1
    • manager_disk = Disk size in GB for the Manager nodes - default: 100
  • Worker Options
    • num = Number of Workers for the Cluster - default: 2
    • worker_machine_type = Google Cloud Machine Type for the Worker nodes - default: n1-standard-1
    • worker_disk = Disk size in GB for the Worker nodes - default: 100

How it works

These scripts are simple wrappers around a set of Deployment Manager templates.

It launches a VM for the Swarm Manager, and a Managed Instance Group for the workers.

This allows you to dynamically scale the number of workers as well as easily create Network Load Balancers that target the worker nodes.

Docker-Machine is used to connect to the Manager node over a secure TLS connection

Notes:

  • This is not an official Google product
  • This is not an official Docker product
  • Only tested on OSX

Fault Tolerance

#!/usr/bin/env bash
for i in $(docker node ls --format {{.Hostname}} -f role=worker);
do 
  docker node promote ${i};
done

Next

  • More control