GloballogicPractices / ECS-Kafka

Guide to run a highly available kafka cluster on ECS backed by Netflix's exhibitor for Zookeeper management
MIT License
30 stars 12 forks source link

HA Kafka cluster on ECS


-- Three node kafka cluster which includes HA zookeeper
-- EFS volumes mounted and used by both Kafka & Zookeeper
-- Scalable - Easy horizontal scaling for Kafka nodes


alt text


This repository
Pre-requisites


Deployment architecture


alt text


NOTE: Kong can be deployed as a proxy server using code from https://github.com/GloballogicPractices/ECS-Kong

Deployment


What is deployed?

  1. VPC - Three private subnets and three public subnets
  2. One ECS Cluster ( Kafka private subnets respectively)
  3. A bastion node.
  4. AWS Log group and log stream
  5. EBS Volumes of 50G attached to each Cassandra node using cloud-init
  6. Route53 for private hosted zone
  7. EFS as backing storage

Deployment procedure

  1. Ensure pre-requisites are met
  2. Decide a region where this needs to be deployed
  3. This guides a cluster in a region with 3 AZs. You can reduce the number in terraform.tfvars file
  4. Ensure a private key is available in AWS
# Prepare your environment ( Terraform and Ansible )
# Change directory to terraform/environments/development
# We are considering a sample development environment
# Update secrets.tf file with your public key

$ cat secrets.tf
aws_key_name = "test-cluster-key"
aws_key_path = "~/.ssh/test-cluster-key.pem"
// Can be generated using
// ssh-keygen -y -f mykey.pem > mykey.pub
keypair_public_key = "ssh-rsa publickey" # Replace this with public key corresponding to your private key in AWS

# You can use any authentication procedures mentioned here https://www.terraform.io/docs/providers/aws/

$ export AWS_ACCESS_KEY_ID="anaccesskey"
$ export AWS_SECRET_ACCESS_KEY="asecretkey"
$ export AWS_DEFAULT_REGION="us-west-2"

terraform.tfvars for your infra

/*
 Variables for deploying stack
--------------------------------
- ACM certificates have to pre-exist
*/

// General
region            = "eu-central-1" #Select a region based on your preference
vpc_name          = "Custom-VPC"
vpc_cidr          = "10.2.0.0/16"
// This is for generated ssh.cfg if you want to get into the instance
proxy_cidr        = "10.2.*"

/*
Environment keyword is important
- This will become suffix for your clusters
- Ansible roles for deployments are called based on the environment
- For simplicity we keep this as development.
*/

environment       = "development"

# AZs are combintation of az length + subnet cidrs
public_sub_cidr   = ["10.2.0.0/24","10.2.1.0/24","10.2.2.0/24"]
private_sub_cidr  = ["10.2.3.0/24","10.2.4.0/24","10.2.5.0/24"]
azs               = ["eu-central-1a","eu-central-1b","eu-central-1c"]

// You can reduce the size if you do not want to incur cost
bastion_instance_type        = "t2.micro"
kafka_instance_type          = "t2.medium"

# Ansible auto ssh - used when you want to do host level
# configuration
ansible_ssh_user  = "ec2-user"
ansible_user      = "ansible"

// For public facing sites and ELBs
// Applications will be accessible from these IPs only
control_cidr = "52.45.0.0/16,138.5.0.0/16"

# ECS Kafka cluster
kafka_asg_max_size = 3
kafka_asg_min_size = 3
kafka_asg_desired_size = 3

// Same as vpc cidr. Can change upon vpc peering
private_sub_control_cidr ="10.2.0.0/16"

// Kafka EFS
// Zookeeper config is stored in a sub directorty
// under kafka directory
efs_kafka_data_dir  = "/kafka-data"
Plan and setup
terraform plan -var-file="secrets.tf"
# If successful then
terraform apply -varf-file="secrets.tf"
## There should be no manual intervention required.
Note