Posts

Showing posts from November, 2016

Using Python/Boto List number of instances associated with each Security Group in AWS

List number of instances associated with each Security Group

import boto

ec2 = boto.connect_ec2()

sgs = ec2.get_all_security_groups()

for sg in sgs:
    print(sg.id + '\t' + sg.name  + '\t\t\t' +  str(len(sg.instances())))


Show Running Instances on AWS including key/tag pairs

import boto
import json, ast

ec2 = boto.connect_ec2()
reservations = ec2.get_all_reservations(
    filters={'instance-state-name': 'running'})
for reservation in reservations:
    for instance in reservation.instances:
        print instance.id + ', '+ instance.instance_type + ', ' + str(ast.literal_eval(json.dumps(instance.tags)) )

Create a swarm cluster on AWS with Docker 1.12 (swarm mode) running two test services

Create a swarm cluster on AWS with Docker 1.12 (swarm mode) running two test services

Tools required:
docker 1.12.0
docker-machine 0.8.0
docker-compose 1.8.0
Kitematic 0.12.0
Boot2Docker ISO 1.12.0
VirtualBox 5.0.24
AWS CLI 1.7.36

AWS CLI assumes credenitals already set
c:\users\xxxx\.aws\credentials
[default]
aws_secret_access_key=xxxxxxxxx
aws_access_key_id=xxxxxxxxxxxx

Spin up swarm cluster (swarm mode) in AWS

docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-manager
docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-node-1
docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-node-2
docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-node-3
docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-node-4
docker-machine create --driver amazonec2 --amazonec2-region eu-west-1   aws-swarm-node-5

docker-machine ip aws-swarm-manager > manager_…

Create a swarm cluster with Virtualbox with Docker 1.12 (swarm mode) running two test services

Create a swarm cluster with Docker 1.12 swarm mode running two test services

docker 1.12.0
docker-machine 0.8.0
docker-compose 1.8.0
Kitematic 0.12.0
Boot2Docker ISO 1.12.0
VirtualBox 5.0.24

docker-machine create --driver virtualbox swarm-manager
docker-machine create --driver virtualbox swarm-node-1
docker-machine create --driver virtualbox swarm-node-2
docker-machine create --driver virtualbox swarm-node-3
docker-machine create --driver virtualbox swarm-node-4
docker-machine create --driver virtualbox swarm-node-5

docker-machine ip swarm-manager > manager_ip.txt
set /p MANAGER_IP=< manager_ip.txt

docker-machine ssh swarm-manager docker swarm-manager init --advertise-addr %MANAGER_IP%

docker-machine ssh swarm-manager docker swarm join-token --quiet manager >manager_token.txt
set /p MANAGER_TOKEN=<manager_token.txt

docker-machine ssh swarm-manager docker swarm join-token --quiet worker >worker_token.txt
set /p WORKER_TOKEN=<worker_token.txt

docker-machine ssh swarm-n…

Bootstrap setup Docker Engine in Swarm

Image
docker-machine create -d virtualbox local

@FOR /f "tokens=*" %i IN ('docker-machine env local') DO @%i


docker run swarm create

docker-machine create -d virtualbox --swarm --swarm-master --swarm-discovery

token://b5a6bbbe593a7a888f01183e47e60eb5     swarm-manager

docker-machine create -d virtualbox --swarm --swarm-discovery

token://b5a6bbbe593a7a888f01183e47e60eb5 swarm-node-1

docker-machine create -d virtualbox --swarm --swarm-discovery

token://b5a6bbbe593a7a888f01183e47e60eb5 swarm-node-2

docker-machine create -d virtualbox --swarm --swarm-discovery

token://b5a6bbbe593a7a888f01183e47e60eb5 swarm-node-3

@FOR /f "tokens=*" %i IN ('docker-machine env --swarm swarm-manager') DO @%i

docker-machine ls



docker info



Containers: 5
 Running: 5
 Paused: 0
 Stopped: 0
Images: 4
Server Version: swarm/1.2.5
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 4
 swarm-manager: 192.168.99.105:2376
  └ ID: V…

Basic Docker SWARM Cluster with Consul, Vagrant, Docker Toolbox and Virtual Box

Below will help run a swarm cluster locally using Vagrant.

This will create and setup 5 vagrant machines in a private network (10.0.7.0/24)

Consul Master: 10.0.7.10
Swarm Manager: 10.0.7.11
Swarm node 1: 10.0.7.12
Swarm node 2: 10.0.7.13
Swarm node 3: 10.0.7.14

The steps were tested using the following
docker toolbox 1.11.1
docker 1.11.1
vagrant 1.7.2
docker-machine 0.7.0
docker-compose 1.7.0
Kitematic 0.10.2
Boot2Docker ISO 1.11.1
VirtualBox 4.3.26


Batch File to Bootstrap

mkdir c:\sd

git clone https://github.com/deviantony/vagrant-swarm-cluster.git

cd vagrant-swarm-cluster

BATCH File .\startup-swarm.bat

vagrant up --provider virtualbox

docker -H 10.0.7.11:2375 run -d --restart always --name consul1 --net host consul agent -server -bind 10.0.7.11 -client 10.0.7.11 -

retry-join 10.0.7.11 -retry-join 10.0.7.12 -retry-join 10.0.7.13 -retry-join 10.0.7.14 -bootstrap-expect 3

docker -H 10.0.7.12:2375 run -d --restart always --name consul2 --net host consul agent -server -bind 10.0.7.12 -cl…