Docker Swarm

Create a Manager Node:

$docker-machine create -d amazonec2 --swarm --amazonec2-region ap-southeast-1 --amazonec2-zone a --amazonec2-vpc-id vpc-12112 --amazonec2-ssh-keypath [SSH-PRIV-KEY-FILE] master

Note: Public Key should also be present in the same directory.

Create 2 Slave Nodes:

$docker-machine create -d amazonec2 --swarm --amazonec2-region ap-southeast-1 --amazonec2-zone a --amazonec2-vpc-id vpc-121212 --amazonec2-ssh-keypath [SSH-PRIV-KEY-FILE] slave1
$docker-machine create -d amazonec2 --swarm --amazonec2-region ap-southeast-1 --amazonec2-zone a --amazonec2-vpc-id vpc-121212 --amazonec2-ssh-keypath [SSH-PRIV-KEY-FILE] slave2

To default docker commands to Manager machine:

$docker-machine env master

Login to master and configure it as Manager node:

$docker-machine ssh master

curl http://169.254.169.254/latest/meta-data/public-ipv4

$docker swarm init --advertise-addr [PUBLIC-IP]

To add a worker to this swarm, run the following command:

$docker swarm join \
--token SWMTKN-1-34t11111111111111111021crh0xwoktwxzwb \
PUBLIC-IP:2377

To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
Login to Slave and execute the above command to add as a worker.

 


DEPLOY A SERVICE


 

NOTE: To resolve to the container based on the service name you provide, you have to create separate networking with overlay driver and use that driver for service creation(use –publish option to expose the port outside).

$docker network create --driver overlay my_net
$docker service create --replicas 2 --network my_net -p 80:80 --name web --mount type=bind,src=/etc/hostname,dst=/usr/share/nginx/html/index.html,readonly nginx
  • This will resolve the name “web” to a virtual IP inside the container but it will not be accessible outside the containers.
  • This will load Nginx containers in both master and slave.

Log into one of the containers

$apt-get udpate
$apt-get install dns-utils curl net-tools
$nslookup web
$ifconfig

The IPs of nslookup and ifconfig are different, the IP of nslookup is Virtual IP.

This will RR between containers running on the same host only.
Status Check of Service:

$docker service ls
$docker service ps web

To scale up a service:

$docker service scale web=5

To remove the whole setup

$docker service rm web

 

 

SWARM has a built-in load balancer, why another load balancer?

SWARM does not have:

  1. SSL Termination
  2. Content Based routing
  3. Access control and authorization
  4. Rewrites and redirects.
  5. More on Nginx – Advance LB Algorithms, Multiprotocol support, Advanced logging, limits, scripting, security.
    (Native mod-security available for Nginx.)

[BLOG Incomplete]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s