Skip to content

abhipsnl/cockroachdb-on-aws

Repository files navigation


Logo

Cockroachdb on AWS

Details instractions, on how to setup CockroachDB on AWS ( EC2 )
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Quick Demo
  4. Setup S3 backend
  5. Generate ssh keys for cockroachDB
  6. Setup cockroachDB on AWS
  7. Test the Connection
  8. Cleanup
  9. License
  10. Contact
  11. Acknowledgements

About The Project

This artifact will help you to deploy Cockroachdb on AWS ( EC2 ).

Scope of Work

  • This is not production ready
  • bastion host will be hosted on public subnet and cockroachdb instance will be hosted on private subnet.
  • Loadbalancer to route requests to all the nodes on port 26257
  • In this terraform project , cockroachdb service is not being deployed as a systemd

Overview

  • Setup S3 backend for terraform state. details
  • Generate ssh-keygen for Cockroachdb instances. details
  • Setup Cockroachdb on AWS EC2. details
  • terraform modules for this assignment. details

Quick Demo

quick 3 min 42 sec demo video

ready-to-upload

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

AWS Account An active AWS account.

aws cli ( >= 2.1.28) aws cli need to be installed. Need help ?.

terraform (>= v0.14.7) terraform cli need to be installed. Need help ?

Github code for this assignment here

General setup

git clone https://github.com/sharmajee1/cockroachdb-on-aws.git
cd cockroachdb-on-aws

Setup S3 backend

! Skip this step only if you already have S3 backend setup

if above steps are done, please perform below steps.

cd terraform-s3-backend
@@ setup your default variables `👉` variables.tf under terraform-s3-backend @@

Readme.md

# Once above steps are done, please perform below commands
terraform init
terraform plan -out=your_plan_name.tfplan
terraform apply "your_plan_name.tfplan"
@@ Copy `state_bucket_arn` URL from above execution, this will be required for `Setup cockroachDB on AWS` step. @@
#example
state_bucket_arn = "arn:aws:s3:::abhishek-temp-terraform-backend"

Generate ssh keys for cockroachDB

! Skip this step only if you already have ssh keys ready for this setup.
# From base dir `cockroachdb-on-aws` go inside scripts dir.
cd scripts
bash create-ssh-keygn.sh
Above script will create ./ssh and ssh-keys, please see below example.
scripts/ssh
├── cockroachdb-node
└── cockroachdb-node.pub

Setup cockroachDB on AWS

Go back to base dir cockroachdb-on-aws From base dir perform below steps.

cd deploy-cockroachdb-om-aws-ec2
! Before performing next steps , please update your state.tf, details can be found from step `Setup S3 backend`
# Example
terraform {
  backend "s3" {
    bucket         = "abhishek-temp-terraform-backend"
    region         = "us-east-1"
    key            = "terraform-state"
    profile        = "dev"
    dynamodb_table = "terraform-lock"
  }
}
! Before performing next steps , please update your aws profile name for `environment_to_profile_map` variable in variables.tf
# Example
variable "environment_to_profile_map" {
  type = map
  description = "Map aws cli profile based on the workspace"
  default = {
    default = "dev"
    dev     = "dev"
    qa      = "aws-qa-profile"
    staging = "aws-staging-profile"
    prod    = "aws-prod-profile"
  }
}
! Before performing next steps , please update your ssh keys for `private_key_path` and `public_key_path` variable in variables.tf
variable "private_key_path" {
  default = "/Users/abhishek.sh/personal-proj/cockroachdb-on-aws/scripts/ssh/cockroachdb-node"
}

variable "public_key_path" {
  default = "/Users/abhishek.sh/personal-proj/cockroachdb-on-aws/scripts/ssh/cockroachdb-node.pub"
}

Execute the final steps

# Once above steps are done, please perform below commands
terraform init
terraform plan -out=cockroachdb_setup.tfplan
terraform apply "cockroachdb_setup.tfplan"

Test the Connection

@@ Copy the `bastion_public_ip` from above execution. @@
bastion_public_ip = "34.195.119.112"
id = [
  "i-0beac6f4d8a904091",
  "i-0959b35c961e34364",
]
@@ Copy the `lb_dns_name` name from above execution. @@

Login to bastion server, execute below command from your local server.

ssh -i <pem-file> ubuntu@<bastion_public_ip>

From bastion server execute below command.

cockroach node status --insecure --host=<lb_dns_name>

cleanup

Once you are done with your testing, you can destroy your deployments

terraform destroy "cockroachdb_setup.tfplan"

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Author abhishek sharma profile Project Link https://github.com/sharmajee1/cockroachdb-on-aws.git

Acknowledgements

About

Deploy cockroachdb on AWS, IaC

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published