This is a simple application that uses SQLite3 as the main database.
┌─────────────────────────────────────────────────────────────────────┐
│ DEVELOPMENT ENVIRONMENT │
├─────────────────────────────────────────────────────────────────────┤
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ WSL2 │ │ Docker │ │ │ │
│ │ │ │ Desktop │ │ IDE │ │
│ └──────────┘ └──────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ APPLICATION STACK │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Frontend │────▶│ Backend │────▶│ Database │ │
│ │ │ │ │ │ │ │
│ │ HTML/CSS/JS │ │ Node.js + │ │ SQLite3 + │ │
│ │ │ │ Express.js │ │ Redis Cache │ │
│ │ │ │ │ │ │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ MONITORING STACK │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Prometheus │────▶│ Grafana │ │ Node Exporter │ │
│ │ │ │ │ │ │ │
│ │ Metrics │ │ Dashboards & │ │ System Metrics │ │
│ │ Collection │ │ Visualization│ │ (CPU/Memory) │ │
│ │ │ │ │ │ │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ KUBERNETES ORCHESTRATION │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Minikube │────▶│ Helm │────▶│ Rancher │ │
│ │ │ │ │ │ │ │
│ │ Local K8s │ │ Package │ │ Cluster Mgmt │ │
│ │ Cluster │ │ Management │ │ & Monitoring │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ SECURITY & QUALITY │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ Trivy │ │ GitHub │ │ Jest │ │
│ │ │ │ Actions │ │ │ │
│ │ Vulnerability │ │ CI/CD │ │ Unit Testing │ │
│ │ Scanner │ │ Pipeline │ │ Framework │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────┐
│ CLOUD DEPLOYMENT │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌───────────────┐ ┌──────────────┐ ┌─────────────────┐ │
│ │ AWS VPC │────▶│ AWS EKS │────▶│ AWS ECR │ │
│ │ │ │ │ │ │ │
│ │ Infrastructure│ │ Kubernetes │ │ Container Image │ │
│ │ (Terraform) │ │ Cluster │ │ Registry │ │
│ └───────────────┘ └──────────────┘ └─────────────────┘ │
│ │
│ ┌───────────────┐ │
│ │ CodePipeline │ │
│ │ │ │
│ │ CI/CD │ │
│ │ Automation │ │
│ └───────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
Frontend:
- HTML5, CSS3, JavaScript (Vanilla)
- Responsive design with custom styling
- Real-time item management interface
Backend:
- Node.js runtime environment
- Express.js web framework
- RESTful API design
- Prometheus metrics integration
Database:
- SQLite3 for persistent data storage
- Redis for caching and session management
- Database health monitoring endpoints
Containerization & Orchestration:
- Docker for application containerization
- Kubernetes (Minikube) for local orchestration
- Helm charts for package management
- Rancher for cluster management
Monitoring & Observability:
- Prometheus for metrics collection
- Grafana for data visualization and dashboards
- Node Exporter for system metrics
- Custom application metrics
DevOps & Security:
- GitHub Actions for CI/CD automation
- Trivy for vulnerability scanning
- Jest for unit testing
- Docker image optimization
Cloud Infrastructure:
- AWS VPC for network isolation
- AWS EKS for managed Kubernetes
- AWS ECR for container registry
- AWS CodePipeline for deployment automation
- Terraform for infrastructure as code
- User Request → Frontend (HTML/CSS/JS)
- API Calls → Backend (Express.js)
- Data Operations → SQLite3 Database
- Caching → Redis Cache
- Metrics Collection → Prometheus
- Visualization → Grafana Dashboards
- System Monitoring → Node Exporter
- Node.js
- Docker
- Minikube
- Kubernetes CLI (
kubectl
) - Helm
- Rancher (for Kubernetes cluster management)
- Trivy
- WSL 2 installed on your Windows machine.
- Docker Desktop installed and configured to work with WSL 2.
-
Start Docker Desktop: Ensure Docker Desktop is running and configured to use WSL 2.
-
Access Rancher: Open your browser and navigate to:
-
Clone the repository:
git clone <repository_url> cd simpleApplication
-
Install dependencies:
npm install
-
Copy the
.env.example
file to.env
and update the values as needed:cp .env.example .env
-
Start the application locally:
npm start
-
Start Minikube:
minikube start
-
Configure your shell to use Minikube's Docker daemon:
eval $(minikube docker-env)
-
Build the Docker image for the application:
docker build -t simple-application:sqlite .
-
Verify the image exists in Minikube's Docker environment:
docker images
-
Deploy the application using Helm:
helm install my-app ./simple-app
-
Verify the deployment:
kubectl get pods kubectl get services
-
Access the application:
minikube service my-app-simple-app
-
Update the replica count in the Helm chart: Open
simple-app/values.yaml
and setreplicaCount
to the desired number of replicas:replicaCount: 3
-
Apply the updated Helm chart:
helm upgrade my-app ./simple-app
-
Verify the scaled deployment:
kubectl get pods
-
Test the application: Access the service URL provided by Minikube and verify that the application is running across multiple replicas.
Trivy is a vulnerability scanner for container images, file systems, and Git repositories. It helps identify security issues in your application dependencies and container images.
-
Install Trivy: Follow the installation instructions for your operating system from the official Trivy documentation.
-
Scan the Application's Docker Image: After building the Docker image for the application, use Trivy to scan it:
trivy image simple-application:sqlite
-
Review the Scan Results: Trivy will output a list of vulnerabilities, categorized by severity (e.g., CRITICAL, HIGH, MEDIUM, LOW). Address the critical and high-severity issues first.
-
Automate Scanning: Integrate Trivy into your CI/CD pipeline to ensure that container images are scanned automatically during the build process.
-
Scan Local Files or Directories: You can also scan your project directory for vulnerabilities:
trivy fs .
-
Keep Trivy Updated: Regularly update Trivy to ensure it has the latest vulnerability database:
trivy --update
By incorporating Trivy into your workflow, you can enhance the security of your application and container images.
PORT
: The port on which the application will run (default: 2019)SQLITE_DB_PATH
: The path to the SQLite database file (default:data/items.db
)
GET /items
: Get all itemsGET /items/:id
: Get an item by IDPOST /items
: Create a new itemPUT /items/:id
: Update an itemDELETE /items/:id
: Delete an item
GET /health
: Check if the application is runningGET /db/health
: Check if the SQLite database is connectedGET /db/test
: Test database operations
This application includes a complete monitoring stack with Prometheus for metrics collection and Grafana for visualization.
-
Deploy monitoring components:
chmod +x deploy-monitoring.sh ./deploy-monitoring.sh
-
Verify monitoring deployment:
kubectl get pods -n monitoring kubectl get services -n monitoring
After deployment, you can access the monitoring services:
-
Prometheus:
http://<MINIKUBE_IP>:30000
- Metrics collection and querying interface
- View application and system metrics
-
Grafana:
http://<MINIKUBE_IP>:32000
- Username:
admin
- Password:
admin123
- Pre-configured with Prometheus as data source
- Username:
To get your Minikube IP:
minikube ip
The application exposes metrics at /metrics
endpoint including:
- HTTP request count
- Average request duration
- Application uptime
- Node.js version information
- Application Metrics: Custom metrics from your Node.js application
- System Metrics: CPU, memory, disk usage via Node Exporter
- Kubernetes Metrics: Pod and cluster metrics
- Auto-discovery: Prometheus automatically discovers pods with proper annotations
- Access Grafana at the URL shown after deployment
- Login with admin credentials
- Create new dashboards or import existing ones
- Use PromQL queries to visualize metrics
Example PromQL queries:
http_requests_total
- Total HTTP requestsrate(http_requests_total[5m])
- Request rate per secondhttp_request_duration_ms
- Average response time
- Run the tests:
npm test
This updated README.md
includes steps for setting up a Minikube cluster, deploying the application using Helm, scaling the application to multiple replicas, and monitoring with Prometheus and Grafana. It also provides instructions for testing and accessing the application and monitoring services.