Skip to content

corbtastik/mongodb-pro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongodb-pro

Local MongoDB Enterprise environment with Ops Manager and Kubernetes Operator on macOS (Apple Silicon). Demonstrates API-driven automation and operational excellence with MongoDB Ops Manager.

Architecture

┌─────────────────────────────────────────────────────────────┐
│  macOS (Apple Silicon)                                      │
│                                                             │
│  ┌───────────────────────────────────────────────────────┐  │
│  │  OrbStack                                             │  │
│  │                                                       │  │
│  │  ┌─────────────────────────────────────────────────┐  │  │
│  │  │  VM: opsmanager (Ubuntu 22.04, x86_64 Rosetta)  │  │  │
│  │  │  - MongoDB 8.0 AppDB (3-node replica set)       │  │  │
│  │  │  - Ops Manager 8.0                              │  │  │
│  │  │  - http://opsmanager.orb.local:8080             │  │  │
│  │  └─────────────────────────────────────────────────┘  │  │
│  │                                                       │  │
│  │  ┌─────────────────────────────────────────────────┐  │  │
│  │  │  Kubernetes (OrbStack built-in)                 │  │  │
│  │  │  - MongoDB Enterprise Kubernetes Operator       │  │  │
│  │  └─────────────────────────────────────────────────┘  │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

Prerequisites

  • macOS 15+ on Apple Silicon
  • OrbStack installed
    • Rosetta enabled (Settings → System → Use Rosetta)
    • Memory limit: 16+ GB recommended (Settings → System → Memory)
    • Kubernetes enabled (Settings → Kubernetes → Enable)
  • Homebrew installed (for Helm)

Setup Options

This project supports two deployment methods:

Method Best For Guide
Shell Scripts Learning, manual control This README
Terraform Automation, IaC, demos terraform/USAGE.md

Shell Script Setup

Step 1: Clone the Repository

git clone https://github.com/corbtastik/mongodb-pro.git
cd mongodb-pro

Step 2: Create the Ops Manager VM

Creates an x86_64 Ubuntu VM using Rosetta emulation (required because Ops Manager is x86_64 only).

./scripts/01-create-opsmanager-vm.sh

Step 3: Install MongoDB AppDB

Installs MongoDB 8.0 as a 3-node replica set. This serves as the backend database for Ops Manager.

./scripts/02-install-appdb.sh

Step 4: Install Ops Manager

Downloads and installs Ops Manager 8.0.

./scripts/03-install-opsmanager.sh

Step 4a: Configure TLS (Optional)

Enables HTTPS with a self-signed certificate. Recommended for security-conscious demos.

./scripts/03a-configure-tls.sh

This will:

  • Generate a self-signed CA and server certificate
  • Configure Ops Manager to use HTTPS on port 8443
  • Export the CA certificate for Kubernetes operator use

After running, access Ops Manager at https://opsmanager.orb.local:8443 (browser will show certificate warning).

Step 5: Configure Ops Manager (UI)

Open Ops Manager in your browser:

Complete initial setup:

  1. Register - Create your admin account (first user becomes admin)
  2. Configure - Accept defaults or configure SMTP if desired
  3. Create Organization - e.g., "myorg"
  4. Create API Key:
    • Go to: Organization → Access Manager → API Keys → Create API Key
    • Description: "automation"
    • Permissions: Organization Owner
    • Copy the Public Key and Private Key
    • Add to Access List: 192.168.139.0/24

Step 6: Configure Environment

cp .env.example .env

Edit .env with your Ops Manager values:

# Use HTTPS URL if Step 4a was run, otherwise HTTP
OPS_MANAGER_URL=http://opsmanager.orb.local:8080
# OPS_MANAGER_URL=https://opsmanager.orb.local:8443

OPS_MANAGER_ORG_ID=<your-24-char-org-id>
OPS_MANAGER_API_PUBLIC_KEY=<your-public-key>
OPS_MANAGER_API_PRIVATE_KEY=<your-private-key>

Where to find these:

  • Org ID: Organization → Settings → Organization ID
  • API Keys: Created in Step 5

Step 7: Deploy Kubernetes Operator

Installs the MongoDB Enterprise Kubernetes Operator and creates necessary secrets.

./scripts/04-setup-k8s-operator.sh

Step 8: Verify Setup

# Ops Manager is accessible
curl -s -o /dev/null -w "%{http_code}\n" http://opsmanager.orb.local:8080

# Operator is running
kubectl get pods -n mongodb

# API credentials work
./scripts/create-project.sh test-project

If all commands succeed, you're ready to deploy MongoDB clusters.


Deploy MongoDB

# 1. Create project in Ops Manager
./scripts/create-project.sh my-project

# 2. Generate Kustomize overlay
./scripts/new-overlay.sh my-project                    # Standalone (default)
./scripts/new-overlay.sh my-project --type ReplicaSet  # 3-node replica set

# 3. Deploy
kubectl apply -k k8s/overlays/my-project

# 4. Check status
kubectl get mongodb,pods -n mongodb-my-project

# 5. Connect (after Running)
mongosh 'mongodb://dbUser:MongoDBPass123!@192.168.139.2:<nodeport>/admin'

Each deployment gets its own isolated namespace (mongodb-<project-name>).


Demo

See docs/DEMO.md for a 30-minute walkthrough demonstrating:

  • API-driven project creation
  • Declarative MongoDB deployment
  • Operational excellence with Ops Manager

Daily Operations

Stop Environment (Preserves Data)

./scripts/stop-all.sh

Start Environment

./scripts/start-all.sh

Teardown

Destroys everything including all data. Use when you want to start fresh.

./scripts/teardown.sh

To set up again, start from Step 2.


Troubleshooting

Ops Manager not accessible

# Check VM is running
orb list

# Check Ops Manager service
orb -m opsmanager -u root systemctl status mongodb-mms

Operator not starting

# Check operator logs
kubectl logs deployment/mongodb-enterprise-operator -n mongodb

# Verify secrets exist
kubectl get secrets -n mongodb

API calls failing (401/403)

  • Verify .env credentials match Ops Manager
  • Ensure 192.168.139.0/24 is in API key access list
  • Regenerate API key if needed

MongoDB pods not starting

# Check MongoDB resource status
kubectl describe mongodb -n mongodb

# Check operator logs for errors
kubectl logs deployment/mongodb-enterprise-operator -n mongodb --tail=100

Project Structure

mongodb-pro/
├── scripts/
│   ├── 01-create-opsmanager-vm.sh   # Create VM
│   ├── 02-install-appdb.sh          # Install MongoDB AppDB
│   ├── 03-install-opsmanager.sh     # Install Ops Manager
│   ├── 03a-configure-tls.sh         # Configure TLS (optional)
│   ├── 04-setup-k8s-operator.sh     # Deploy K8s Operator
│   ├── create-project.sh            # Create Ops Manager project (API)
│   ├── new-overlay.sh               # Generate Kustomize overlay
│   ├── start-all.sh                 # Start environment
│   ├── stop-all.sh                  # Stop environment
│   └── teardown.sh                  # Destroy everything
├── terraform/
│   ├── control-plane/local/         # Ops Manager + K8s Operator (IaC)
│   ├── data-plane/local/            # MongoDB clusters (IaC)
│   ├── modules/                     # Reusable Terraform modules
│   └── USAGE.md                     # Terraform guide
├── k8s/
│   ├── base/                        # Kustomize base templates
│   └── overlays/                    # Per-project configurations
├── docs/
│   └── DEMO.md                      # Demo walkthrough
├── .env.example                     # Environment template
└── README.md

Mini Demo

Quick setup from scratch to a running MongoDB standalone:

# 1. Setup infrastructure
./scripts/01-create-opsmanager-vm.sh
./scripts/02-install-appdb.sh
./scripts/03-install-opsmanager.sh
./scripts/03a-configure-tls.sh

# 2. Manual: Open https://opsmanager.orb.local:8443
#    - Create admin user
#    - Create organization
#    - Create API key (Organization Owner, add 192.168.139.0/24 to access list)
#    - Update .env with HTTPS URL and credentials

# 3. Deploy K8s operator
./scripts/04-setup-k8s-operator.sh

# 4. Deploy MongoDB
./scripts/create-project.sh demo-01
./scripts/new-overlay.sh demo-01
kubectl apply -k k8s/overlays/demo-01

# 5. Verify
kubectl get mongodb,pods -n mongodb-demo-01 -w

# 6. Load sample data and run queries
./scripts/load-sample-data.sh demo-01
./scripts/query-sample-data.sh demo-01

# 7. Connect
mongosh 'mongodb://dbAdmin:MongoDBPass123%21@192.168.139.2:30100/admin'

Resources

About

MongoDB Enterprise environment with Ops Manager and Kubernetes Operator on macOS (Apple Silicon).

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors