GitXplorerGitXplorer
v

training-consul-cluster

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
34bc8a77fce1c99504d1948c489a500f82dc114f

added diagram to improve on understandability

vventh committed 8 years ago
Unverified
f0c8459ac233a8edd2d1c028d678813828d1cf04

corrected typos and ports

vventh committed 8 years ago
Unverified
a16c331d79a1c484e716e95b0a150d3eaae46419

improved on consul cluster setup

vventh committed 8 years ago
Unverified
8d2a76a8af28b3f97ebec27cca7e638a41c5b1f4

added cloudformation for consul server cluster

vventh committed 8 years ago
Unverified
f97b630328098b2f1850a0e924e97afce454e443

added consul starting and stopping command along with description

vventh committed 8 years ago
Unverified
a5c7dd8fdc2ebc8eec1a02ac8709be43d851fb85

decoupled consul agent from consul server cluster; agent lays near by its service

vventh committed 8 years ago

README

The README file for this repository.

training-consul-cluster

Just a spike to learn how consul is working

Consul on docker

This part consists of:

  • three consul servers which are clustered
  • consul-aware-service along with consul agent
  • consul-aware-service-consumer along with consul agent

To start consul cluster run:

gradle consulStart

To stop consul cluster run:

gradle consulStop

Consul http console is exposed on urls as follows:

Consul service aware provides following services:

Consul service aware consumer provides following services:

Consul on AWS

Consul cluster on AWS consists of two parts:

  • consul server cluster and
  • consul agents deployed besides a specific service

Consul Server Cluster on AWS

In directory ./consul-server-cluster/aws there are two cloudformation templates:

  • consul-permission.yaml - exports ConsulServerMemberInstanceProfile used to localize consul server leader in the cluster
  • consul-infrastructure.yaml - spins up consul server cluster infrastructure and uses exported ConsulServerMemberInstanceProfile to lookup consul server leader

After creating consul server cluster ui is provided on the address as follows:

  • http://pResourceNamePrefix.pHostedZoneName - where pResourceNamePrefix and pHostedZoneName are cloud formation parameters values (e.g.: http://awesome-consul.awesome.zone)

In order to create consul server cluster by aws cli use a bash file as follows:

#!/bin/bash

AWS_PROFILE=default

stack_name=awesome-consul
iam_stack_name=${stack_name}-iam
OWNER='your email'
SSH_KEY=your-ssh-key

VPC_ID=your-vpc-id
# comma separated list of your subnets
SUBNETS=subnet-00000000,subnet-00000001

# base AMI ID - needs to have yum
AMI=ami-f9619996

# your hosted zone in Route53
HOSTED_ZONE=awesome.zone.

# SSH access cidr
SSHAccessCIDR=10.0.0.0/8

# HTTP access cidr
HTTPAccessCIDR=10.0.0.0/8

if aws --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${iam_stack_name} &> /dev/null ; then
    echo "updates ${iam_stack_name}"
    aws --profile ${AWS_PROFILE} cloudformation update-stack \
          --stack-name=${iam_stack_name} \
          --template-body=file://$(pwd)/consul-permission.yaml \
          --capabilities CAPABILITY_NAMED_IAM CAPABILITY_IAM \
          --tags \
              Key=Owner,Value=${OWNER}
else
    echo "creates ${iam_stack_name}"
    aws --profile ${AWS_PROFILE} cloudformation create-stack \
          --stack-name=${iam_stack_name} \
          --template-body=file://$(pwd)/consul-permission.yaml \
          --capabilities CAPABILITY_NAMED_IAM CAPABILITY_IAM \
          --tags \
              Key=Owner,Value=${OWNER} && \

        aws --profile ${AWS_PROFILE} cloudformation wait stack-create-complete \
              --stack-name=${iam_stack_name} || \

        aws --profile ${AWS_PROFILE} cloudformation delete-stack \
              --stack-name=${iam_stack_name}
fi

if aws --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${stack_name} &> /dev/null ; then
    echo "updates ${stack_name}"
    aws --profile ${AWS_PROFILE} cloudformation update-stack \
          --stack-name=${stack_name} \
          --template-body=file://$(pwd)/consul-infrastructure.yaml \
          --parameters \
              ParameterKey=pResourceNamePrefix,ParameterValue=${stack_name} \
              ParameterKey=pKeyName,ParameterValue=${SSH_KEY} \
              ParameterKey=pDesiredCapacity,ParameterValue=3 \
              ParameterKey=pInstanceType,ParameterValue=t2.medium \
              ParameterKey=pVpcId,ParameterValue=${VPC_ID} \
              ParameterKey=pSubnetIds,ParameterValue=\"${SUBNETS}\" \
              ParameterKey=pClusterMemberAmiId,ParameterValue=${AMI} \
              ParameterKey=pHostedZoneName,ParameterValue=${HOSTED_ZONE} \
              ParameterKey=pEcsIAMStack,ParameterValue=${iam_stack_name} \
              ParameterKey=pSSHAccessCIDR,ParameterValue=${SSHAccessCIDR} \
              ParameterKey=pHTTPAccessCIDR,ParameterValue=${HTTPAccessCIDR} \
          --tags \
              Key=Owner,Value=${OWNER}
else
    echo "creates ${stack_name}"
    aws --profile ${AWS_PROFILE} cloudformation create-stack \
          --stack-name=${stack_name} \
          --template-body=file://$(pwd)/consul-infrastructure.yaml \
          --parameters \
              ParameterKey=pResourceNamePrefix,ParameterValue=${stack_name} \
              ParameterKey=pKeyName,ParameterValue=${SSH_KEY} \
              ParameterKey=pDesiredCapacity,ParameterValue=3 \
              ParameterKey=pInstanceType,ParameterValue=t2.medium \
              ParameterKey=pVpcId,ParameterValue=${VPC_ID} \
              ParameterKey=pSubnetIds,ParameterValue=\"${SUBNETS}\" \
              ParameterKey=pClusterMemberAmiId,ParameterValue=${AMI} \
              ParameterKey=pHostedZoneName,ParameterValue=${HOSTED_ZONE} \
              ParameterKey=pEcsIAMStack,ParameterValue=${iam_stack_name} \
              ParameterKey=pSSHAccessCIDR,ParameterValue=${SSHAccessCIDR} \
              ParameterKey=pHTTPAccessCIDR,ParameterValue=${HTTPAccessCIDR} \
          --tags \
          Key=Owner,Value=${OWNER} || \
    aws --profile ${AWS_PROFILE} cloudformation delete-stack \
          --stack-name=${stack_name}
fi