Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions documentdb-playground/aws-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ export GITHUB_TOKEN="your-token"
- `--skip-operator` - Skip operator installation (default)
- `--install-operator` - Install operator (requires GitHub authentication)
- `--deploy-instance` - Deploy operator + instance (requires GitHub authentication)
- `--node-type TYPE` - EC2 instance type (default: `m7g.large`, Graviton/ARM)
- `--eks-version VER` - Kubernetes/EKS version (default: `1.35`)
- `--spot` - Use Spot-backed managed nodes (dev/test only — see warning below)
- `--tags TAGS` - Cost allocation tags as comma-separated `key=value` pairs (default: `project=documentdb-playground,environment=dev,managed-by=eksctl`)

#### Spot Instance Warning

When using `--spot`, AWS can terminate instances at any time with only 2 minutes notice.
This **will interrupt your database** and require recovery. Only use Spot for dev/test
workloads where brief downtime is acceptable. Spot is disabled by default.

#### Custom Tags

Tags are passed to AWS for cost allocation tracking in Cost Explorer:

```bash
# Default tags
./scripts/create-cluster.sh
# Tags: project=documentdb-playground,environment=dev,managed-by=eksctl

# Custom tags via flag
./scripts/create-cluster.sh --tags "project=myproj,team=platform,costcenter=1234"

# Or via environment variable
export CLUSTER_TAGS="project=myproj,team=platform"
./scripts/create-cluster.sh
```

### delete-cluster.sh
```bash
Expand Down Expand Up @@ -119,13 +146,13 @@ export GITHUB_TOKEN="your-token"
## What Gets Created

**create-cluster.sh builds:**
- EKS cluster with 2 managed nodes (m5.large)
- EKS cluster with managed nodes (default: `m7g.large` Graviton/ARM, 3 nodes)
- EBS CSI driver for storage
- AWS Load Balancer Controller
- cert-manager for TLS
- Optimized storage classes

**Estimated cost:** ~$140-230/month (always run delete-cluster.sh when done!)
**Estimated cost:** ~$140-230/month (always run delete-cluster.sh when done!) — use `--spot` for ~70% savings on dev/test.

## Support

Expand Down
88 changes: 74 additions & 14 deletions documentdb-playground/aws-setup/scripts/create-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ set -e # Exit on any error
# Configuration
CLUSTER_NAME="documentdb-cluster"
REGION="us-west-2"
NODE_TYPE="m5.large"
K8S_VERSION="${K8S_VERSION:-1.35}"
NODE_TYPE="${NODE_TYPE:-m7g.large}"
NODES=3
NODES_MIN=1
NODES_MAX=4

# Cost-optimization configuration
# USE_SPOT: when "true", eksctl provisions Spot-backed managed nodes (dev/test only).
# CLUSTER_TAGS: comma-separated key=value pairs passed to AWS for cost allocation in Cost Explorer.
USE_SPOT="${USE_SPOT:-false}"
CLUSTER_TAGS="${CLUSTER_TAGS:-project=documentdb-playground,environment=dev,managed-by=eksctl}"

# DocumentDB Operator Configuration
# For production: use documentdb/documentdb-operator (official)
OPERATOR_GITHUB_ORG="documentdb"
Expand Down Expand Up @@ -58,6 +65,22 @@ while [[ $# -gt 0 ]]; do
GITHUB_TOKEN="$2"
shift 2
;;
--node-type)
NODE_TYPE="$2"
shift 2
;;
--eks-version|--k8s-version)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the eks-version and k8s-version same term internally for AWS customers?

K8S_VERSION="$2"
shift 2
;;
--spot)
USE_SPOT="true"
shift
;;
--tags)
CLUSTER_TAGS="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
Expand All @@ -70,13 +93,23 @@ while [[ $# -gt 0 ]]; do
echo " --region REGION AWS region (default: us-west-2)"
echo " --github-username GitHub username for operator installation"
echo " --github-token GitHub token for operator installation"
echo ""
echo "Cost-optimization options:"
echo " --node-type TYPE EC2 instance type (default: m7g.large, Graviton/ARM)"
echo " --eks-version VER Kubernetes/EKS version (default: 1.35)"
echo " --spot Use Spot-backed managed nodes (DEV/TEST ONLY - can be terminated)"
echo " --tags TAGS Cost allocation tags as key=value pairs (comma-separated)"
echo " (default: project=documentdb-playground,environment=dev,managed-by=eksctl)"
echo ""
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Create basic cluster only (no operator, no instance)"
echo " $0 --install-operator # Create cluster with operator, no instance"
echo " $0 --deploy-instance # Create cluster with instance (auto-enables operator)"
echo " $0 --github-username user --github-token ghp_xxx --install-operator # With GitHub auth"
echo " $0 --node-type m5.large # Use x86 instance type instead of Graviton"
echo " $0 --spot --tags \"project=myproj,team=platform\" # Spot dev cluster with custom tags"
exit 0
;;
*)
Expand Down Expand Up @@ -146,24 +179,43 @@ check_prerequisites() {
# Create EKS cluster
create_cluster() {
log "Creating EKS cluster: $CLUSTER_NAME in region: $REGION"

# Check if cluster already exists
if eksctl get cluster --name $CLUSTER_NAME --region $REGION &> /dev/null; then
warn "Cluster $CLUSTER_NAME already exists. Skipping cluster creation."
return 0
fi

# Create cluster with basic configuration
eksctl create cluster \
--name $CLUSTER_NAME \
--region $REGION \
--node-type $NODE_TYPE \
--nodes $NODES \
--nodes-min $NODES_MIN \
--nodes-max $NODES_MAX \
--managed \

if [ "$USE_SPOT" == "true" ]; then
warn "============================================================"
warn "SPOT INSTANCES ENABLED - FOR DEV/TEST USE ONLY"
warn "AWS can terminate Spot instances at any time with 2 minutes"
warn "notice. This WILL interrupt your database and require recovery."
warn "Do NOT use Spot for production or long-running workloads."
warn "============================================================"
fi

local EKSCTL_ARGS=(
--name "$CLUSTER_NAME"
--region "$REGION"
--version "$K8S_VERSION"
--nodes "$NODES"
--nodes-min "$NODES_MIN"
--nodes-max "$NODES_MAX"
--managed
--with-oidc

--tags "$CLUSTER_TAGS"
)

if [ "$USE_SPOT" == "true" ]; then
# Multiple instance types improve Spot availability; all Graviton to match the default.
EKSCTL_ARGS+=(--spot --instance-types "m7g.large,m6g.large,r7g.large,r6g.large,c7g.large,c6g.large")
else
EKSCTL_ARGS+=(--node-type "$NODE_TYPE")
fi

eksctl create cluster "${EKSCTL_ARGS[@]}"

if [ $? -eq 0 ]; then
success "EKS cluster created successfully"
else
Expand Down Expand Up @@ -528,11 +580,15 @@ print_summary() {
echo "=================================================="
echo "Cluster Name: $CLUSTER_NAME"
echo "Region: $REGION"
echo "Kubernetes: $K8S_VERSION"
echo "Node Type: $NODE_TYPE"
echo "Spot Instances: $USE_SPOT"
echo "Tags: $CLUSTER_TAGS"
echo "Operator Installed: $INSTALL_OPERATOR"
echo "Instance Deployed: $DEPLOY_INSTANCE"
echo ""
echo "✅ Components installed:"
echo " - EKS cluster with managed nodes"
echo " - EKS cluster with managed nodes ($NODE_TYPE)"
echo " - EBS CSI driver"
echo " - AWS Load Balancer Controller"
echo " - cert-manager"
Expand Down Expand Up @@ -567,6 +623,10 @@ main() {
log "Configuration:"
log " Cluster: $CLUSTER_NAME"
log " Region: $REGION"
log " Kubernetes: $K8S_VERSION"
log " Node Type: $NODE_TYPE"
log " Spot Instances: $USE_SPOT"
log " Tags: $CLUSTER_TAGS"
log " Install Operator: $INSTALL_OPERATOR"
log " Deploy Instance: $DEPLOY_INSTANCE"
echo ""
Expand Down