Docker Swarm Auto-Clustering and Scaling

Togglebox is partnering with Jelastic to provide Docker Swarm Auto-Clustering and Scaling with PaaS Power Armor. Docker Engine nodes that are run in a swarm mode constitute a fault-tolerant platform for application hosting with built-in cluster management features.

It helps to keep your dockerized services constantly running and available  across different servers and data centers. Docker swarm provides such extra benefits as automatic disaster recovery, zero-downtime updates, etc.

Running a cluster of Docker nodes could be fraught with some difficulties as this technology is rather new and thus still requires considerable system administrator’s efforts for its handling.

We will describe how to avoid the complexity of manual swarm building and maintenance with a dedicated Docker Swarm Cluster package for one-click installation.

This solution allows setting up a ready-to-go dockerized cluster within minutes.

 

Get acquainted with the following articles on Docker Engine implementation first, as it represents a fundamental Docker Swarm component:

Docker Swarm Cluster Topology Specifics

The structure of the environment is composed of two layers (node groups) with the following prescribed roles:

  • Manager – maintains the desired state of your swarm and all of the services that are run on it
  • Worker – receives and executes tasks, that are dispatched from Manager node(s)

During installation, you can declare the desired number of containers for each layer (so-called “replicas”) and choose one of the available installation types:

  • setting up a bare cluster to subsequently deploy the required Docker image manually
  • create a swarm with the already deployed image based on the provided compose file

By default, each node has a pre-allocated room of resources for growth upon the necessity (up to 8 GiB RAM per container).

You only pay for the consumed capacities due to the pay-per-use pricing approach.

The cluster memory consumption in idle mode is less than 128 MiB (1 cloudlet) per container, which is charged accordingly to your hosting provider pricing.

A reliable Docker swarm cluster of 8 nodes can be hosted for a price of just 8 cloudlets!

Docker Swarm consumption

As an additional benefit all containers are equally automatically distributed across host nodes (i.e. physical servers) to ensure extra high availability of your application.

Docker Swarm distribution across host nodes

 

Before installing this package, please consider the following points:

  • The chosen platform should contain environment region(s) with native Docker container support enabled. You can check a list of the supported providers via the link.
  • The included option of public IP attachment to the manager nodes is provided for billing users only.

Swarm Cluster Load Alerts & Scaling

Docker Swarm Cluster stands for convenient resource consumption statistics tracking, which allows automatic notification about load spikes or drops.

1. The cluster is provided with load alerts that notify you via email about high consumption of some resource (CPU, RAM, network, etc.):

Docker Swarm load alerts

They help to keep you up-to-date with the cluster state and swiftly respond in case of any issues or necessity to enlarge capacities.

2. Enlarge the vertical scaling limit (32 cloudlets by default) or add new nodes into the swarm. Both actions can be configured via topology wizard:

Docker Swarm scaling

Take advantage of swarm mode’s fault-tolerance features, Docker recommends implementing an odd number of manager nodes according to your organization’s high-availability requirements.

3. Also, you can pre-configure the automatic horizontal scaling of both manager and worker nodes, which is based on the current cluster load.

 

For example, scaling can be performed according to the following conditions:

  • add node(s) if RAM or CPU usage is >70% for at least 5 minutes
  • remove node(s) if RAM or CPU usage is <40% for at least 5 minutes

Docker Swarm automatic horizontal scaling

In order to keep the odd number of managers, it is recommended to scale the layer by pairs of nodes.

4. You can manually attach nodes from different environment regions or even installations to your swarm cluster.

Docker Swarm cluster installed

Read more about Docker Engine Inclusion into Swarm Cluster.

Docker Swarm Installation

The Docker Swarm installation from Togglebox UI Marketplace is fully automated and requires just a few simple steps.

 

1. Click the Marketplace button at the top of the dashboard pane and search for the Docker Swarm Cluster solution within the opened window.

Docker Swarm marketplace

Hover over the appropriate plank and click Install to continue.

2. In a second, the installation frame will be opened.

Docker Swarm installation

To get the cluster you need:

  • Docker Version – version of the Docker Engine CE image
  • Manager Nodes – an odd number of manager nodes to be included in a cluster (with public IP being automatically attached to each container)
  • Worker Nodes – number of worker nodes to be included in a cluster
  • choose deployment type:
    • Clean Cluster – to create a bare cluster; as an extra option, you can simultaneously install the Portainer management UI with Let’s Encrypt SSL certificates for convenient operating with cluster nodes

Docker Swarm clean cluster

    • Deploy Stack YML – to perform the docker stack deploy operation after the cluster creation and instantly install the required dockerized services specified in the appropriate compose YML file:

Docker Swarm YML deploy

  • Environment – a name for your environment
  • Display Name – optional alias to be displayed for environment
  • Region – preferred environment region (if multiple ones are available)

As an example, we’ll create a bare Docker swarm cluster with 3 manager5 worker nodes, and Portainer UI with Let’s Encrypt SSL.

Once configurations are stated, click Install and wait for a few minutes for and it will automatically perform.

3. After your cluster is deployed, the corresponding environment will appear on the dashboard.

Docker Swarm environment

 

Docker Swarm Connection

After the successful installation, your cluster can be accessed in the following ways for further management:

  • Portainer UI

In case you’ve installed a clean cluster with the Portainer UI & Let’s Encrypt SSL, the appropriate management panel can be accessed by simply opening your environment in a browser via HTTPS (the 443 port).

Docker Swarm Portainer

Note: By default, connection to Portainer is secured with a testing Let’s Encrypt SSL certificate, thus you might be shown the warning that it’s not trusted by your browser. This does not actually affect the Portainer functionality – you just need to confirm you do want to access the requested page.

Docker Swarm certificate

The required actions could differ depending on a used browser – for example, in Google Chrome, you’ll need to expand the Advanced section and click on the Proceed to {env_URL} link.

The appropriate authentication credentials to enter the Portainer itself can be found within the corresponding email notification you’ve received after the Docker swarm creation.

  • SSH Gate

Use SSH Gate to connect to one of the Manager nodes within your Docker swarm environment to start managing the whole cluster.

You can establish an SSH connection by clicking on the Web SSH button.

Docker Swarm ssh gate

An alternative option is to connect via any preferred SSH client (you’ll need to upload your public key to the dashboard).

Custom Domain & SSL Protection

You need to bind a custom domain name for your application and to protect this domain with a trusted SSL certificate.

Note: The Let’s Encrypt SSL certificate installed alongside the Portainer UI is suitable for that particular service only (not for the whole environment).

1. You can review and fulfill the requirements to add SSL protection by clicking the Change Environment Topology button for the required environment (i.e. your Docker swarm cluster).

Docker Swarm change topology2. Switch to the SSL section. Here, you can see the pre-requirements of the custom SSL configuration for the environment.

Docker Swarm enable ssl

Click the Enable button to make the required adjustments automatically and Apply these changes.

3. A load balancer node with an external IP address will be added to the environment, allowing to add a custom domain name. Follow the linked guide to view an example of how to:

  • purchase a custom domain for your application
  • configure DNS record to point from this domain to your Togglebox environment

4. Now, you can proceed with the SSL configuration.

Two options are available:

After these manipulations, your Docker swarm cluster will be ready for production.

Read more about services and applications deployment to the swarm cluster.