CockroachDB is a distributed SQL database that aims to make it simple to build, deploy, and operate globally-scaled applications. It is designed to be highly available, survive data center outages, and maintain consistent performance across a geographically distributed database cluster.
One of the key features of CockroachDB is its ability to automatically shard data across multiple nodes in a cluster, allowing it to scale horizontally as more nodes are added.
This repo provides a Terraform Module that can be used to deploy CRDB multi node database cluster in a single EKS cluster using CockroachDB Kubernetes Operator. It his also uses cert-manager to secure node communication with TLS certificate.
- An active AWS account with required permission to deploy resources in Kubernetes cluster
- A running EKS cluster with version v1.23+ , EKS Node should have kubernets label
node=cockroachdb - EBS CSI Driver v1.19.0+ installed in the EKS cluster
- An Understanding of Terraform and usage.
- Terraform CLI with version 1.0.0+
- Install Kubectl
- AWS CLI v2.9.18+
- A web browser that is supported for use with the AWS Management Console. (See the list of supported browsers)
- git clone https://github.com/aws-samples/crdb-cluster-eks-terraform.git
- Update variable.tf under main folder to the required value. For more information on all variables, refer to the README file inside
modules/crdbfolder.
- terraform init
- terraform apply
- Verify if kubectl is installed. Follow instructions to install kubectl
kubectl version
- Set the eks context using aws cli
aws eks update-kubeconfig --name <eks_cluster_name> --region <AWS_Region_Name>
-
Verify number of CRDB pods using
kubectl get pods -n <namespace>
NAME READY STATUS RESTARTS AGE
cockroach-operator-655fbf7847-zn9v8 1/1 Running 0 30m
cockroachdb-0 1/1 Running 0 24m
cockroachdb-1 1/1 Running 0 24m
cockroachdb-2 1/1 Running 0 24m
- 3 cockroach dB pods will be running as the default value in the variable.tf is set to 3. This may vary based on the value set on variable.tf file.
Scale up/down:
- Increase/decrease the number of nodes for managed node group in ./main/variable.tf and perform
terraform apply
Note - Due to POD anti-affinity rule, only one CRDB Pod can run in one EKS worker note. Hence,use EKS autoscaler or Karpenter for autoscaling worker nodes automcatically to run the additional CRDB nodes (POD)
- For example, if number of nodes is increased from 3 to 4, you would see 4 pods are running after executing
terraform apply
kubectl get pods -n <namespace>
NAME READY STATUS RESTARTS AGE
cockroach-operator-655fbf7847-zn9v8 1/1 Running 0 30m
cockroachdb-0 1/1 Running 0 24m
cockroachdb-1 1/1 Running 0 24m
cockroachdb-2 1/1 Running 0 24m
cockroachdb-3 1/1 Running 0 30s
To tear down, run
terraform destroy
| Name | Version |
|---|---|
| aws | 4.66.0 |
| Name | Source | Version |
|---|---|---|
| common-tags | ../modules/common-tags | n/a |
| crdb | ../modules/crdb | n/a |
| Name | Type |
|---|---|
| aws_region.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| eks_cluster_name | Name of the EKS Cluster | string |
"demo" |
no |
| number_of_nodes | Number of nodes to be deployed | number |
3 |
no |
| region | set the region for deployment | string |
"us-east-2" |
no |
No outputs.
See CONTRIBUTING for more information.
