Skip to content

Latest commit

 

History

History
419 lines (327 loc) · 14.2 KB

File metadata and controls

419 lines (327 loc) · 14.2 KB

Implementation Summary: CloudWatch Integration & Security Group Automation

Overview

This implementation adds AWS CloudWatch metrics integration to the Velora Admin Dashboard and automates security group configuration for EKS clusters to enable NodePort access without manual AWS Console intervention.

Changes Made

1. Updated EKS Setup Guide

File: /app/Velora-cli-engine-0.0.2/EKS_SETUP_guide_new.md

Key Features:

  • ✅ Automatic security group configuration for NodePort range (30000-32767)
  • ✅ Three deployment methods:
    • Quick setup with one-line command
    • Configuration file approach
    • Automated script
  • ✅ No manual AWS Console steps required
  • ✅ Complete documentation for CloudWatch setup

Usage Example:

# Create cluster and configure security groups automatically
eksctl create cluster \
  --name arnav-velora2 \
  --region ap-south-1 \
  --nodes 2 \
  --node-type t3.medium \
  --managed

# Auto-configure security groups
NODE_SG=$(aws ec2 describe-security-groups \
  --filters "Name=tag:aws:eks:cluster-name,Values=arnav-velora2" \
  --query 'SecurityGroups[?contains(GroupName, `node`)].GroupId' \
  --output text \
  --region ap-south-1)

aws ec2 authorize-security-group-ingress \
  --group-id $NODE_SG \
  --protocol tcp \
  --port 30000-32767 \
  --cidr 0.0.0.0/0 \
  --region ap-south-1

2. Enhanced Backend with CloudWatch Integration

File: /app/Velora-cli-engine-0.0.2/backend/server_new.py

New Endpoints:

  1. Admin Authentication: POST /api/admin/authenticate

    • Password protection for admin dashboard
    • Default password: velora-cli-engine (configurable via .env)
  2. CloudWatch Metrics: POST /api/admin/cloudwatch/metrics

    • Fetches real-time metrics from AWS CloudWatch
    • Supports time ranges: 1h, 24h, 7d, 30d
    • Metrics included:
      • Node CPU utilization
      • Node memory utilization
      • Network traffic
      • Disk I/O
      • Pod CPU utilization
      • Pod memory utilization
  3. Pod Statistics: GET /api/admin/pods/stats

    • Total pods, running, pending, failed
    • Detailed pod information (name, namespace, status, containers, node)
    • Falls back to CloudWatch if kubectl unavailable
  4. Cost Estimate: GET /api/admin/cost/estimate

    • EKS control plane costs
    • Node group costs by instance type
    • Total cost per hour, day, and month
    • Regional pricing (default: ap-south-1)

Required Dependencies (already in requirements.txt):

  • boto3>=1.34.129 - AWS SDK for Python

3. New Admin Dashboard Component

File: /app/Velora-cli-engine-0.0.2/frontend/src/components/AdminDashboard_new.js

Features:

Authentication Layer

  • Password-protected access
  • Toggle password visibility
  • Session-based authentication

Time Range Selector

  • 1 hour (real-time)
  • 24 hours
  • 7 days
  • 30 days

CloudWatch Metrics Visualization

  • CPU Utilization Chart: Area chart showing node CPU usage over time
  • Memory Utilization Chart: Area chart showing memory consumption
  • Network Traffic Chart: Line chart showing network bytes transferred
  • Disk Utilization Chart: Area chart showing filesystem usage

Statistics Dashboard

  • Total pods count
  • Current CPU usage percentage
  • Current memory usage percentage
  • Monthly cost estimate

Pod Management

  • Live pod status (running, pending, failed)
  • Detailed pod table with:
    • Pod name
    • Namespace
    • Status badge
    • Container count
    • Node assignment

Cost Breakdown

  • EKS control plane cost
  • Node group costs by instance type
  • Total cost per hour/day/month
  • Regional pricing information

Developer Activity

  • Active developers list
  • Services per developer
  • Developer email and profile

Required Dependencies:

  • recharts - For charts and graphs (needs to be installed)

4. Environment Configuration Documentation

File: /app/Velora-cli-engine-0.0.2/ENV_CONFIGURATION.md

Complete guide for setting up all required environment variables:

  • AWS credentials and IAM policies
  • CloudWatch configuration
  • Admin password setup
  • Security best practices

Required Environment Variables

Add to /app/Velora-cli-engine-0.0.2/backend/.env:

# AWS Configuration (NEW)
AWS_REGION=ap-south-1
AWS_ACCESS_KEY_ID=your_aws_access_key_here
AWS_SECRET_ACCESS_KEY=your_aws_secret_key_here

# EKS Cluster Configuration (NEW)
EKS_CLUSTER_NAME=arnav-velora2

# Admin Dashboard Password (NEW)
ADMIN_PASSWORD=velora-cli-engine

# Existing variables (keep as is)
MONGO_URL=mongodb://localhost:27017
DB_NAME=velora
CORS_ORIGINS=http://localhost:3005
GITHUB_TOKEN=your_github_token
DOCKER_USERNAME=your_docker_username
DOCKER_TOKEN=your_docker_token
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your_email
SMTP_PASSWORD=your_password
FRONTEND_URL=http://localhost:3005

AWS IAM Policy Requirements

The AWS credentials need these managed policies attached:

  • CloudWatchReadOnlyAccess - For fetching metrics
  • AmazonEKSReadOnlyAccess - For cluster information
  • AmazonEC2ReadOnlyAccess - For security groups and node info

Installation Steps

1. Install Frontend Dependencies

cd /app/Velora-cli-engine-0.0.2/frontend
yarn add recharts

2. Configure Backend

cd /app/Velora-cli-engine-0.0.2/backend

# Add required environment variables to .env file
cat >> .env << 'EOF'

# AWS Configuration
AWS_REGION=ap-south-1
AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE
AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY_HERE

# EKS Configuration
EKS_CLUSTER_NAME=arnav-velora2

# Admin Password
ADMIN_PASSWORD=velora-cli-engine
EOF

# Install dependencies (if not already installed)
pip install -r requirements.txt

3. Enable CloudWatch Container Insights

# Enable logging on EKS cluster
eksctl utils update-cluster-logging \
  --enable-types=all \
  --cluster=arnav-velora2 \
  --region=ap-south-1 \
  --approve

# Install CloudWatch agent
kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/quickstart/cwagent-fluentd-quickstart.yaml

4. Start Services

# Terminal 1: Start backend with new server
cd /app/Velora-cli-engine-0.0.2/backend
python3 -m uvicorn server_new:app --host 0.0.0.0 --port 8002 --reload

# Terminal 2: Start frontend
cd /app/Velora-cli-engine-0.0.2/frontend
yarn start

5. Access Admin Dashboard

  1. Open browser: http://localhost:3005/admin
  2. Enter password: velora-cli-engine
  3. View real-time CloudWatch metrics!

Testing the Implementation

Test Backend Endpoints

# Test health check
curl http://localhost:8002/api/health

# Test authentication
curl -X POST http://localhost:8002/api/admin/authenticate \
  -H "Content-Type: application/json" \
  -d '{"password":"velora-cli-engine"}'

# Test CloudWatch metrics
curl -X POST http://localhost:8002/api/admin/cloudwatch/metrics \
  -H "Content-Type: application/json" \
  -d '{"time_range":"1h"}'

# Test pod statistics
curl http://localhost:8002/api/admin/pods/stats

# Test cost estimate
curl http://localhost:8002/api/admin/cost/estimate

Test Security Group Configuration

# Deploy a service
velora deploy test-service

# Service should be accessible immediately at http://<NODE_IP>:<NODE_PORT>
# No manual security group configuration needed!

Architecture Overview

┌─────────────────────────────────────────────────────────┐
│                     Frontend (React)                     │
│  ┌──────────────────────────────────────────────────┐  │
│  │         AdminDashboard_new.js                    │  │
│  │  • Password Authentication                       │  │
│  │  • Time Range Selector                          │  │
│  │  • CloudWatch Charts (Recharts)                 │  │
│  │  • Pod Statistics Display                       │  │
│  │  • Cost Breakdown                               │  │
│  └──────────────────────────────────────────────────┘  │
└────────────────────┬────────────────────────────────────┘
                     │ HTTP Requests
                     ▼
┌─────────────────────────────────────────────────────────┐
│                  Backend (FastAPI)                       │
│  ┌──────────────────────────────────────────────────┐  │
│  │              server_new.py                       │  │
│  │  • Admin Auth Endpoint                          │  │
│  │  • CloudWatch Metrics API                       │  │
│  │  • Pod Stats API                                │  │
│  │  • Cost Estimate API                            │  │
│  └──────────────────────────────────────────────────┘  │
└────────────────────┬────────────────────────────────────┘
                     │ boto3 SDK
                     ▼
┌─────────────────────────────────────────────────────────┐
│                   AWS Services                           │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐ │
│  │  CloudWatch  │  │     EKS      │  │     EC2      │ │
│  │   Metrics    │  │   Cluster    │  │  Security    │ │
│  │              │  │     Info     │  │   Groups     │ │
│  └──────────────┘  └──────────────┘  └──────────────┘ │
└─────────────────────────────────────────────────────────┘

Key Improvements

1. Security Group Automation

  • Before: Manual AWS Console configuration required
  • After: Automatic configuration during cluster setup
  • Benefit: Saves time, reduces errors, improves developer experience

2. CloudWatch Integration

  • Before: No visibility into cluster metrics
  • After: Real-time CPU, memory, network, and disk metrics
  • Benefit: Better monitoring, faster troubleshooting, informed scaling decisions

3. Cost Tracking

  • Before: Unknown operational costs
  • After: Real-time cost breakdown and estimates
  • Benefit: Budget management, cost optimization opportunities

4. Admin Dashboard

  • Before: Basic dashboard with limited information
  • After: Comprehensive dashboard with password protection
  • Benefit: Enhanced security, better insights, professional UI

Troubleshooting

Issue: No metrics showing

Solution:

  1. Verify CloudWatch Container Insights is enabled
  2. Wait 5-10 minutes for initial metrics collection
  3. Check AWS credentials have correct permissions

Issue: Authentication failed

Solution:

  1. Check ADMIN_PASSWORD in backend .env file
  2. Restart backend server after changing password

Issue: Cost estimate not accurate

Solution:

  1. Verify EKS cluster name matches EKS_CLUSTER_NAME in .env
  2. Check AWS credentials have EKS read permissions
  3. Costs are estimates based on instance types and AWS pricing

Issue: Pod statistics not available

Solution:

  1. Install and configure kubectl
  2. Or enable CloudWatch Container Insights
  3. Check backend logs for specific errors

Future Enhancements

Potential improvements for future versions:

  1. Alerts: Set up CloudWatch alarms for high CPU/memory
  2. Historical Reports: Export metrics to CSV/PDF
  3. Multi-Cluster Support: Monitor multiple EKS clusters
  4. Custom Dashboards: User-defined metric combinations
  5. Cost Optimization Suggestions: AI-powered recommendations
  6. Real-time Notifications: Slack/Email alerts for critical events

Files Modified/Created

Created:

  • /app/Velora-cli-engine-0.0.2/EKS_SETUP_guide_new.md
  • /app/Velora-cli-engine-0.0.2/backend/server_new.py
  • /app/Velora-cli-engine-0.0.2/frontend/src/components/AdminDashboard_new.js
  • /app/Velora-cli-engine-0.0.2/ENV_CONFIGURATION.md
  • /app/Velora-cli-engine-0.0.2/IMPLEMENTATION_SUMMARY.md

Original Files (Untouched):

  • /app/Velora-cli-engine-0.0.2/EKS_SETUP_guide.md
  • /app/Velora-cli-engine-0.0.2/backend/server.py
  • /app/Velora-cli-engine-0.0.2/frontend/src/components/AdminDashboard.js

Documentation

All new files are suffixed with _new to preserve original code:

  • EKS_SETUP_guide_new.md - Updated setup guide
  • server_new.py - Enhanced backend
  • AdminDashboard_new.js - New admin dashboard

Original files remain untouched for reference and rollback purposes.

Support

For questions or issues:

  1. Check ENV_CONFIGURATION.md for setup details
  2. Review EKS_SETUP_guide_new.md for cluster configuration
  3. Verify all environment variables are correctly set
  4. Check backend logs: tail -f /var/log/supervisor/backend.*.log

Implementation Complete! 🎉

All requirements have been met:

  1. ✅ Automated security group configuration for NodePort access
  2. ✅ CloudWatch metrics integration for arnav-velora2 cluster
  3. ✅ Pod usage statistics and cost tracking
  4. ✅ Password-protected admin dashboard
  5. ✅ Developer management capabilities
  6. ✅ Real-time and historical data with time range selector
  7. ✅ New files created with _new suffix
  8. ✅ Original code untouched