Giter Site home page Giter Site logo

docker-swarm-demo's Introduction

Docker Swarm POC

This repository contains a POC of Docker Swarm configured in the following manner:

  • 3 Docker hosts (dockerhost[01:03])
    • Run latest Docker daemon
    • Run a Docker Swarm daemon pointed at Consul
    • Run a Registrator daemon pointed at Consul
  • 1 Docker Swarm host (dockerswarm01)
    • Runs Docker Swarm and listens to the Docker port
      • Is the primary interface for the Docker cluster
    • Runs Consul

Requirements

There are a few requirements to get

How to use it

Everything can be tried out using Vagrant once the pre-reqs have been installed. Just follow these simple instructions:

# Stand up the environment and provision the hostfile entries
vagrant up

# Update the `/etc/hosts` files on the VMs
vagrant provision --provision-with hosts

# Set your env variables to point at Vagrant
source bin/env

# Pull images down to the docker hosts.
cd ansible/
ansible-playbook vagrant_docker_images.yml

# Interact with Docker as normal
docker ps
docker run --rm -i -t  ubuntu:latest /bin/bash

TLS

TLS is functional as long as Swarm is configured to use the file type of discovery. After generating the certificates, set the following variables for both the dockerhosts and dockerswarm groups to run TLS:

  • use_tls: true
  • docker_port: 2376

The certificates can be generated and the cluster provisioned using the following commands. Please note: The PKI is included in .gitignore and so will need to be regenerated each time this repo is cloned.

# Generate SSL
./bin/gen_ssl.sh

# Provision the cluster
vagrant up

# Set your env to Vagrant + TLS
source bin/env_tls

# Pull images down to the docker hosts.
./bin/pull_images_tls.sh
ansible-playbook vagrant_docker_images.yml

# Interact with the cluster
docker ps
docker run --rm -i -t  ubuntu:latest /bin/bash

Swarm configuration

The Swarm daemon has a few configuration options that are available. They include:

  • Discovery
  • Scheduling
  • TLS (config described above)

Swarm discovery

Swarm supports multiple discovery mechanisms including:

  • File (supported here)
  • Consul (supported here)
  • EtcD
  • Zookeeper
  • Hosted service (Docker Hub?)

File Discovery: Uses a static file with a list of Docker hosts. Swarm is pointed at this list and will create a cluster based on it's contents. This is the most basic discovery method and is enabled by default in this project (though currently the project is configured for Consul). The format of the list should be the following:

http<s>://< hostname1 >:< port >
http<s>://< hostname2 >:< port >
http<s>://< hostname3 >:< port >
http<s>://< hostname4 >:< port >

Consul Discovery: This configuration mode is what this project is configured to use currently. It relies on Consul's key/value store being located on the Swarm host (dockerswarm01) at /swarm. In addition to maintaining the Swarm cluster, this Consul host also is the endpoint Registrator uses for service discovery under the path /services. You can view the cluster in Consul at: http://dockerswarm01/ui/#/test/kv/swarm/

Swarm Scheduling

At this point in time, Swarm supports two scheduling modes with one in progress:

  • Binpacking: pack a machine based on a static set of resources
  • Random: Pick a host at random
  • Balanced: Pack machines evenly (In-Progress docker-archive/classicswarm#227)

Swarm uses the scheduling configuration in combination with tags in the Docker daemon's startup configs to enable control over how to pack the machines. You can edit the various tags on a machine-by-machine basis by editing the host specific configs found in ansible/host_vars/<hostname>.yml and then specifying a constraint. An example of a Docker run line for a host in the cluster would be:

docker --label zone=external \
  --label disk=ssd \
  -H tcp://0.0.0.0:2375

An example that will start an Nginx container on the above node through Swarm could be:

docker run -d \
  -p 80 \
  -e constraint:zone==external \
  -e constraint:disk==ssd \
  -t nginx:latest

The above configuration will start an Nginx server on a Docker host in the Swarm cluster that has been tagged with zone=external and disk=ssd. Since there are ports published, registrator will also pick this up and upsert a value into the /services/nginx-80 key in Consul with the value of "ipaddress:port" of the running container.

Included Projects

Registrator

Docker Swarm

Consul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.