diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 72e4024..dfee070 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,3 +1,4 @@
+
name: CI
on:
@@ -6,30 +7,38 @@ on:
pull_request:
workflow_dispatch:
schedule:
- - cron: '0 6 * * 1'
+ - cron: "0 6 * * 1"
+
+permissions:
+ contents: read
jobs:
build-and-smoke:
+ name: Build and Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
+
strategy:
- max-parallel: 1
+ fail-fast: false
matrix:
- # Angular 22 requires Node ^22.22.3 || ^24.15.0 || >=26.0.0
- node-version: [24.18.0, 26.5.0]
+ node-version: [22.x, 24.x]
services:
mongodb:
- image: mongo:latest
+ image: mongo:4.4
+ ports:
+ - 27017:27017
options: >-
- --health-cmd "mongosh --eval 'db.adminCommand({ ping: 1 })'"
+ --health-cmd "mongo --quiet --eval 'db.adminCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
- ports:
- - 27017:27017
+
+ env:
+ DATABASE_URI: mongodb://127.0.0.1:27017/meanStackExample?appName=mean-stack-example-ci
+ PORT: 5300
steps:
- - name: Checkout
+ - name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
@@ -37,96 +46,176 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: npm
+ cache-dependency-path: |
+ package-lock.json
+ server/package-lock.json
+ client/package-lock.json
+
+ - name: Display runtime versions
+ run: |
+ node --version
+ npm --version
+
+ # Install dependencies using committed lockfiles
+
+ - name: Install root dependencies
+ run: npm ci --ignore-scripts
- - name: Install dependencies
+ - name: Install server dependencies
+ working-directory: server
run: npm ci
- - name: Build
- env:
- DATABASE_URI: mongodb://localhost:27017/
- run: npm run build
+ - name: Install client dependencies
+ working-directory: client
+ run: npm ci
+
+ # Build
+
+ - name: Build TypeScript server
+ run: npm run build:server
- - name: Server lint tests
- env:
- DATABASE_URI: mongodb://localhost:27017/
+ - name: Build Angular client
+ run: npm run build:client
+
+ # Tests
+
+ - name: Server lint checks
run: npm run test:server
- - name: Integration tests
+ - name: Client unit tests
+ run: npm run test:client -- -- --watch=false
+
+ - name: Server integration tests
run: npm run test:integration
- - name: Seed demo data
- env:
- DATABASE_URI: mongodb://localhost:27017/meanStackExample?appName=mean-stack-example-ci
+ # Database verification
+
+ - name: Seed demo database
run: npm run seed
- - name: Start API
- env:
- DATABASE_URI: mongodb://localhost:27017/meanStackExample?appName=mean-stack-example-ci
- PORT: 5300
+ # Start real API server
+
+ - name: Start API server
run: |
npm run start:server > /tmp/server.log 2>&1 &
echo $! > /tmp/server.pid
- - name: Wait for API health
+ - name: Wait for API health check
run: |
- for i in {1..30}; do
- if curl -fsS http://localhost:5300/healthcheck >/dev/null; then
- echo "API is ready"
+ for i in {1..45}; do
+ if curl -fsS http://127.0.0.1:5300/healthcheck; then
+ echo
+ echo "API is healthy"
exit 0
fi
+
sleep 1
done
- echo "API did not become ready"
+
+ echo "API startup failed"
+ echo "===== SERVER LOGS ====="
cat /tmp/server.log
exit 1
- - name: Smoke check employee list endpoint
- run: curl -fsS http://localhost:5300/employees
+ # API smoke tests
+
+ - name: Smoke test employee endpoint
+ run: |
+ response=$(curl -fsS http://127.0.0.1:5300/employees)
+
+ echo "$response"
+
+ echo "$response" | jq -e \
+ 'type == "array" and length == 5'
- - name: Stop API
+ - name: Stop API server
if: always()
run: |
if [ -f /tmp/server.pid ]; then
- kill "$(cat /tmp/server.pid)" || true
+ SERVER_PID=$(cat /tmp/server.pid)
+ pkill -TERM -P "$SERVER_PID" || true
+ kill "$SERVER_PID" || true
fi
+ echo "API cleanup completed"
+
notify-on-failure:
+ name: Notify CI Failure
needs: build-and-smoke
- if: failure()
+ if: ${{ failure() && github.event_name != 'pull_request' }}
+
runs-on: ubuntu-latest
+
permissions:
issues: write
+
steps:
- - name: File or update CI failure issue for @mongodb-developer/learning-fuel
+ - name: Create or update CI failure issue
uses: actions/github-script@v7
with:
script: |
const title = `CI failure on ${context.ref}`;
+
const body = [
- '@mongodb-developer/learning-fuel the CI workflow failed.',
+ 'The automated CI workflow has failed.',
'',
`Workflow: ${context.workflow}`,
- `Run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
+ `Branch/Ref: ${context.ref}`,
+ `Run ID: ${context.runId}`,
+ `Run URL: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
].join('\n');
- const { data: existing } = await github.rest.issues.listForRepo({
- owner: context.repo.owner,
- repo: context.repo.repo,
- state: 'open',
- labels: 'ci-failure',
- });
- if (existing.length > 0) {
+
+ const owner = context.repo.owner;
+ const repo = context.repo.repo;
+
+ // Ensure the CI failure label exists.
+ try {
+ await github.rest.issues.getLabel({
+ owner,
+ repo,
+ name: 'ci-failure',
+ });
+ } catch (error) {
+ if (error.status !== 404) throw error;
+
+ await github.rest.issues.createLabel({
+ owner,
+ repo,
+ name: 'ci-failure',
+ color: 'd73a4a',
+ description: 'Automated CI workflow failures',
+ });
+ }
+
+ // Find an existing open CI failure issue.
+ const { data: issues } =
+ await github.rest.issues.listForRepo({
+ owner,
+ repo,
+ state: 'open',
+ labels: ['ci-failure'],
+ });
+
+ if (issues.length > 0) {
await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: existing[0].number,
+ owner,
+ repo,
+ issue_number: issues[0].number,
body,
});
+
+ core.info(
+ `Updated existing CI issue #${issues[0].number}`
+ );
} else {
- await github.rest.issues.create({
- owner: context.repo.owner,
- repo: context.repo.repo,
- title,
- body,
- labels: ['ci-failure'],
- });
+ const { data: issue } =
+ await github.rest.issues.create({
+ owner,
+ repo,
+ title,
+ body,
+ labels: ['ci-failure'],
+ });
+
+ core.info(`Created CI issue #${issue.number}`);
}
diff --git a/.gitignore b/.gitignore
index 37ec10d..fdbf316 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,50 @@
-node_modules
-*.env
+# Dependencies
+node_modules/
+**/node_modules/
+
+# Environment files and secrets
+.env
+.env.*
+!.env.example
+*.pem
+*.key
+secrets/
+**/secrets/
+
+# Logs and runtime files
+*.log
+logs/
+npm-debug.log*
+yarn-debug.log*
+pnpm-debug.log*
+
+# Local database backups and data
+backups/
+*.dump
+*.sql.gz
+*.sqlite
+*.sqlite3
+
+# Local Grafana and Kubernetes backups
+grafana-deployment-backup.yaml
+grafana-deployment-backup.yml
+*.backup.yaml
+*.backup.yml
+
+# Build outputs and coverage
+dist/
+build/
+coverage/
+.angular/
+.cache/
+
+# Operating system and editor files
.DS_Store
+Thumbs.db
+.vscode/
+.idea/
+*.swp
+*.swo
+
+# Local Docker image archives
+k8s/*.tar
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..df5972c
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,9 @@
+# Attribution / Modification Notice
+
+This repository is based on the original MongoDB Developer MEAN Stack Example project.
+
+The original project is licensed under the Apache License, Version 2.0.
+
+This repository contains modifications and additions made for a personal DevOps learning project, including Docker/Docker Compose deployment configuration, NGINX configuration, containerization, deployment documentation, troubleshooting documentation, and related infrastructure work.
+
+The original project's copyright and attribution notices remain applicable to the original portions of the work.
diff --git a/README.md b/README.md
index a689bc3..e5346d4 100644
--- a/README.md
+++ b/README.md
@@ -1,189 +1,485 @@
-# MEAN Stack Example: Employee Records App (MongoDB, Express, Angular, Node.js)
+
-A full-stack CRUD application built with MongoDB, Express, Angular, and Node.js (MEAN).
+# MEAN Stack Example — Employee Records Application
-Companion code for the [MEAN Stack Tutorial](https://www.mongodb.com/languages/mean-stack-tutorial?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel).
+

-[](https://github.com/mongodb-developer/mean-stack-example/actions/workflows/ci.yml)
-[](LICENSE)
-[](https://github.com/mongodb-developer/mean-stack-example/stargazers)
+### A full-stack MEAN application with a hands-on DevOps deployment workflow
-## Project Overview
+[](https://angular.dev/)
+[](https://nodejs.org/)
+[](https://expressjs.com/)
+[](https://www.typescriptlang.org/)
+[](https://www.mongodb.com/)
+[](https://www.docker.com/)
+[](https://docs.docker.com/compose/)
+[](https://kubernetes.io/)
+[](https://kind.sigs.k8s.io/)
+[](https://github.com/features/actions)
+[](https://prometheus.io/)
+[](https://grafana.com/)
+[](https://nginx.org/)
-This project demonstrates an employee record tracker:
+[Overview](#overview) • [Architecture](#architecture) • [Screenshots](#screenshots) • [Docker](#run-with-docker-compose) • [Kubernetes](#kubernetes-deployment-with-kind) • [Monitoring](#monitoring)
-- Create records
-- Read records from MongoDB
-- Update records
-- Delete records
+
-The Angular app in `client` calls an Express API in `server`, and data is stored in MongoDB.
+---
-## MEAN Stack Architecture
+## Overview
+
+This repository contains a full-stack **Employee Records Application** built with the **MEAN stack** — MongoDB, Express, Angular, and Node.js — and extended into a practical DevOps project.
+
+The application supports employee record management through CRUD functionality (Create, Read, Update, and Delete). The project focuses on packaging, deploying, operating, and monitoring the application using container and Kubernetes tooling.
+
+### Project highlights
+
+- **Full-stack application:** Angular frontend with a Node.js, Express, and TypeScript REST API.
+- **Containerization:** Separate frontend, backend, and database services using Docker.
+- **Local orchestration:** Docker Compose for multi-container development and testing.
+- **Kubernetes deployment:** Local Kubernetes deployment using Kind and manifests in `k8s/`.
+- **Monitoring foundation:** Backend metrics exposed for Prometheus, with Prometheus and Grafana components included in the Kubernetes manifests.
+- **Continuous Integration:** GitHub Actions workflow for builds, tests, health checks, and smoke tests.
+
+> **Project scope:** The repository includes a GitHub Actions CI workflow. Docker Compose and Kubernetes are separate deployment options. An automated Continuous Deployment (CD) pipeline is not included.
+
+## Contents
+
+- [Overview](#overview)
+- [Architecture](#architecture)
+- [Technology Stack](#technology-stack)
+- [Repository Structure](#repository-structure)
+- [Screenshots](#screenshots)
+- [Run with Docker Compose](#run-with-docker-compose)
+- [Application Request Flow](#application-request-flow)
+- [Kubernetes Deployment with Kind](#kubernetes-deployment-with-kind)
+- [Monitoring](#monitoring)
+- [API Endpoints](#api-endpoints)
+- [Persistence](#persistence)
+- [Security and Configuration Notes](#security-and-configuration-notes)
+- [CI Workflow](#ci-workflow)
+- [Useful Commands](#useful-commands)
+- [Documentation](#documentation)
+- [Known Limitations and Roadmap](#known-limitations-and-roadmap)
+- [Attribution](#attribution)
+- [Author](#author)
+
+## Architecture
+
+### Overall system architecture
+
+The project supports two deployment paths:
+
+1. **Docker Compose** — runs the frontend, backend, and MongoDB as separate containers.
+2. **Kubernetes with Kind** — deploys the application to a local Kubernetes cluster using the supplied manifests.
+
+The backend also exposes metrics for Prometheus monitoring.
+
+
+
+### Architecture diagrams
+
+| Diagram | Description |
+|---|---|
+| [Overall System Architecture](architecture/Overall-System-Architecture.png) | Application components, deployment options, and monitoring |
+| [Application Request Flow](architecture/application-request-flow.png) | Browser requests through NGINX, Express, and MongoDB |
+| [Docker Compose Architecture](architecture/docker-compose-architecture.png) | Compose services, networking, ports, and persistent volume |
+| [Kubernetes Architecture](architecture/kubernetes-architecture.png) | Kind port mapping, Kubernetes Services, Pods, and database PVC |
+| [Monitoring Flow](architecture/monitoring-flow.png) | Backend metrics, Prometheus scraping, and Grafana visualization |
+| [Security & Configuration Architecture](architecture/security-configuration-architecture.png) | Configuration, Secret references, health checks, monitoring, and storage |
+
+> Keep the diagram files at the paths shown above. If a diagram is not available in the repository yet, add it before publishing the corresponding image link. Mermaid source may be maintained in [`docs/architecture.md`](docs/architecture.md).
+
+## Technology Stack
+
+| Layer | Technology | Purpose |
+|---|---|---|
+| Frontend | Angular | Employee records user interface |
+| Web server / reverse proxy | NGINX | Serves Angular assets and proxies `/api/` requests |
+| Backend | Node.js, Express, TypeScript | REST API and application logic |
+| Database | MongoDB | Employee record storage |
+| Containers | Docker | Builds and runs application containers |
+| Container orchestration | Docker Compose | Runs the application services together |
+| Local Kubernetes | Kind, Kubernetes | Local cluster and application orchestration |
+| Metrics | `prom-client`, Prometheus | Exposes and collects backend metrics |
+| Dashboards | Grafana | Visualizes metrics when a data source and dashboard are configured |
+| CI | GitHub Actions | Automates build, test, health-check, and smoke-test jobs |
+
+## Repository Structure
```text
-┌─────────────────────┐ REST (JSON) ┌──────────────────────────┐
-│ Angular (CLI) │ ─────────────────────► │ Express API │
-│ client │ ◄───────────────────── │ server │
-│ :4200 │ │ :5300 │
-└─────────────────────┘ └───────────┬──────────────┘
- │ MongoDB Node.js driver
- ▼
- ┌──────────────────────────┐
- │ MongoDB │
- │ database: meanStackExample
- │ collection: employees │
- └──────────────────────────┘
+mean-stack-example/
+├── .github/
+│ └── workflows/
+│ └── ci.yml
+├── client/
+│ ├── src/
+│ ├── Dockerfile
+│ └── nginx.conf
+├── server/
+│ ├── src/
+│ ├── scripts/
+│ ├── tests/
+│ ├── Dockerfile
+│ └── .env.example
+├── docs/
+│ ├── architecture.md
+│ ├── deployment-guide.md
+│ ├── troubleshooting.md
+│ └── diagrams/
+├── k8s/
+│ ├── app/
+│ ├── monitoring/
+│ ├── kind-config.yaml
+│ └── namespace.yaml
+├── architecture/
+│ └── ... architecture diagrams and banner
+├── screenshots/
+│ └── ... project screenshots
+├── docker-compose.yml
+├── README.md
+├── LICENSE
+└── NOTICE
```
-Stack:
+This is a simplified view of the main files. The repository contains additional application and configuration files.
-- Frontend: Angular 21, Angular Material
-- Backend: Node.js, Express 4, TypeScript, MongoDB Node.js Driver 6
-- Database: MongoDB (`meanStackExample.employees` collection)
+## Screenshots
-## Project Structure
+Screenshots make it easier to understand the application and verify the project setup. Add your own screenshots to the `screenshots/` directory and use the filenames below, or update the paths to match your actual files.
-```text
-client/ # Angular frontend
-server/ # Express API + MongoDB integration
+### 1. Application interface
+
+Show the employee records application running in the browser.
+
+
+
+### 2. Docker Compose services
+
+Show the frontend, backend, and database containers running.
+
+
+
+### 3. Kubernetes deployment
+
+Show the application Pods, Services, and PersistentVolumeClaims.
+
+
+
+### 4. Prometheus targets
+
+Show the backend scrape target and its health status in Prometheus.
+
+
+
+### 5. Grafana dashboard
+
+Add a screenshot after configuring the Prometheus data source and confirming that the dashboard displays real metrics.
+
+
+
+### 6. GitHub Actions CI
+
+Show a successful run of the repository's CI workflow.
+
+
+
+> **Screenshot note:** These are image paths/placeholders for the repository. Add the corresponding image files before expecting them to render on GitHub. Do not present a dashboard or workflow as successful until you have verified it.
+
+## Run with Docker Compose
+
+### Docker Compose architecture
+
+The Docker Compose deployment runs the Angular frontend, Node.js/Express backend, and MongoDB database as separate services.
+
+
+
+### Prerequisites
+
+- Docker Engine
+- Docker Compose plugin
+
+Verify the installation:
+
+```bash
+docker --version
+docker compose version
```
-## Prerequisites
+A local Node.js or MongoDB installation is not required for the containerized deployment.
+
+### 1. Validate the configuration
-- Node.js ^24.18.0
-- npm ^11.16.0
-- A local MongoDB instance or a free [MongoDB Atlas](https://www.mongodb.com/atlas?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) cluster
+Run from the repository root:
+
+```bash
+docker compose config
+```
-## Quick Start and MongoDB Setup
+### 2. Build and start the services
```bash
-# 1) Clone
-git clone https://github.com/mongodb-developer/mean-stack-example.git
-cd mean-stack-example
+docker compose up --build -d
+```
+
+Check service status:
-# 2) Create server environment file
-cp server/.env.example server/.env
+```bash
+docker compose ps
```
-Update `server/.env` with one of the following `DATABASE_URI` values:
+### 3. Open the application
+
+Visit **http://localhost:8080** in your browser.
-Local MongoDB:
+### Docker Compose services
-```env
-DATABASE_URI=mongodb://localhost:27017/
-PORT=5300
+| Service | Container | Port / access | Role |
+|---|---|---|---|
+| `client` | `mean-client` | Host `8080` → container `80` | Angular frontend served by NGINX |
+| `server` | `mean-server` | Host `5300` → container `5300` | Express API |
+| `database` | `mean-db` | Internal port `27017` | MongoDB database |
+
+MongoDB is **not published to a host port** in the supplied Compose configuration. The backend reaches it through Compose service discovery:
+
+```text
+mongodb://database:27017/
```
-Atlas cluster:
+### Docker Compose request path
-```env
-DATABASE_URI=mongodb+srv://:@.mongodb.net/
-PORT=5300
+1. The browser loads the Angular application from `http://localhost:8080`.
+2. NGINX serves the static frontend files.
+3. Requests sent to `/api/` are reverse-proxied to the `server` service on port `5300`.
+4. NGINX removes the `/api/` prefix because the `proxy_pass` target ends with `/`.
+5. Express handles the request and reads or updates employee records in MongoDB.
+6. The API response returns through NGINX to the browser.
+
+For example, `/api/employees` is proxied to `/employees`, matching the backend router mount.
+
+## Application Request Flow
+
+The normal request/response path is:
+
+**Browser → NGINX → Express API → MongoDB → Express API → NGINX → Browser**
+
+
+
+The exact API methods and request payloads are defined in the application source. See the route file and frontend service code before relying on this README as a complete API contract.
+
+## Kubernetes Deployment with Kind
+
+The repository includes Kubernetes manifests under `k8s/` and a Kind configuration that maps host address `127.0.0.1:8081` to node port `30080`.
+
+- The client Service uses NodePort `30080`.
+- The backend and database use internal Kubernetes Services.
+- The backend manifest references a Secret named `mean-mongo-credentials` with the key `DATABASE_URI`.
+
+> **Important:** The database Deployment uses `mongo:4.4` with authentication enabled. Before deploying to a fresh cluster, verify that MongoDB is initialized with credentials consistent with the backend's `DATABASE_URI`. Creating a Kubernetes Secret does not itself create a MongoDB user.
+
+### Kubernetes architecture
+
+
+
+### Deployment overview
+
+The typical workflow is:
+
+1. Create a Kind cluster using `k8s/kind-config.yaml`.
+2. Build the client and server images.
+3. Load those images into the Kind cluster.
+4. Create the required Kubernetes Secret locally.
+5. Apply the namespace, application, and monitoring manifests.
+6. Verify Pods, Services, PVCs, logs, and the Prometheus target.
+7. Open the application at **http://127.0.0.1:8081**.
+
+Follow [`docs/deployment-guide.md`](docs/deployment-guide.md) for the detailed command sequence. Confirm the actual filenames and resource names before running commands; adapt the cluster name to your environment.
+
+## Monitoring
+
+The backend exposes two operational endpoints:
+
+| Endpoint | Purpose |
+|---|---|
+| `GET /healthcheck` | Returns a JSON health status |
+| `GET /metrics` | Exposes Prometheus-format metrics collected by `prom-client` |
+
+The supplied Prometheus configuration scrapes the backend at:
+
+```text
+server.mean-app.svc.cluster.local:5300/metrics
```
-If you are new to Atlas, use the [Atlas quick start guide](https://www.mongodb.com/docs/atlas/getting-started/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) and then paste your connection string into `DATABASE_URI`.
+The Kubernetes manifests include Prometheus and Grafana. Prometheus is configured with short retention and does not have a PVC defined in the supplied manifest. A Grafana PVC manifest is included.
-Optional: seed sample data:
+### Monitoring flow
-```bash
-(cd server && npm install && npm run seed)
+
+
+**Verification before claiming a working dashboard:** check that the Prometheus target is `UP`, confirm Grafana's Prometheus data source is configured, and verify the dashboard displays real metrics. The presence of deployment manifests alone does not prove that a data source or dashboard has been provisioned.
+
+## API Endpoints
+
+| Method | Endpoint | Purpose |
+|---|---|---|
+| `GET` | `/healthcheck` | Backend health status |
+| `GET` | `/metrics` | Prometheus metrics |
+| `GET` | `/employees` | Employee collection route |
+| Other CRUD methods | `/employees` and `/employees/:id` | See the backend route implementation for exact supported methods and behavior |
+
+The frontend uses the `/api/` prefix through NGINX. The proxy removes that prefix before forwarding to Express.
+
+For the precise API contract, inspect `server/src/employee.routes.ts` and the frontend's API service before documenting individual request bodies or status codes.
+
+## Persistence
+
+### Docker Compose
+
+MongoDB data is stored in the named volume:
+
+```text
+mongo-data → /data/db
```
-Start the backend API:
+Stopping the Compose stack normally keeps the named volume:
```bash
-cd server
-npm start
+docker compose down
+docker compose up -d
```
-Start the frontend in a second terminal:
+To delete the Compose-managed volume and its stored data:
```bash
-cd client
-npm install
-npm start
+docker compose down -v
```
-Open `http://localhost:4200`.
+> **Warning:** `docker compose down -v` is destructive for the database volume. Use it only when you intentionally want to remove local database data.
-## GitHub Codespaces and Dev Containers
+### Kubernetes
-GitHub Codespaces is an easy and fast way to get this project running without installing anything locally. It uses a dev container, which is a Docker environment configured for development.
+The MongoDB Deployment references a PersistentVolumeClaim named `mongo-data-pvc`. Check that the PVC is `Bound` before relying on persistent database storage.
-[](https://codespaces.new/mongodb-developer/mean-stack-example?quickstart=1)
+## Security and Configuration Notes
-## REST API Endpoints
+- Do not commit passwords, tokens, full connection strings, or real Secret values.
+- Base64-encoded Kubernetes Secret data is **not encryption**. Treat it as sensitive.
+- The backend Kubernetes manifest references `mean-mongo-credentials` and the key `DATABASE_URI`; create and manage the value locally.
+- Review backup files and old deployment backups before publishing. Remove any artifact containing credentials or private data.
+- MongoDB uses `mongo:4.4` in the supplied Compose and Kubernetes manifests. This is an old release line; plan a compatible, tested upgrade rather than changing the image tag without migration testing.
+- Docker Compose networking and Kubernetes Services provide service-to-service connectivity. Kubernetes NetworkPolicies, firewall rules, HTTPS/TLS, Trivy image scanning, and application RBAC should not be described as implemented unless they are added and verified.
+- The security/configuration diagram documents the repository's configuration references and operational components; it is not a claim that the application is production-hardened.
-Base URL: `http://localhost:5300`
+### Security & Configuration Architecture
-| Method | Endpoint | Description |
-|---|---|---|
-| `GET` | `/healthcheck` | Check API readiness |
-| `GET` | `/employees` | Retrieve all employees |
-| `GET` | `/employees/:id` | Retrieve one employee by ID |
-| `POST` | `/employees` | Create an employee |
-| `PUT` | `/employees/:id` | Update an employee |
-| `DELETE` | `/employees/:id` | Delete an employee |
-
-Example request body for create or update:
-
-```json
-{
- "name": "Jane Smith",
- "position": "Developer",
- "level": "senior"
-}
+
+
+## CI Workflow
+
+The repository includes `.github/workflows/ci.yml`.
+
+The workflow runs on pushes to `main`, pull requests, manual dispatch, and a scheduled trigger. Its jobs include:
+
+- Dependency installation
+- Application build
+- Server tests
+- Integration tests
+- Seeding demo data
+- Starting the API
+- Checking `/healthcheck`
+- Smoke-testing `/employees`
+
+This is **Continuous Integration (CI)**. The supplied workflow does **not** deploy the application to Kubernetes or a cloud environment, so automated Continuous Deployment (CD) is not included.
+
+## Useful Commands
+
+### Docker Compose
+
+```bash
+# Show the resolved Compose configuration
+docker compose config
+
+# Start / rebuild the stack
+docker compose up --build -d
+
+# Check services
+docker compose ps
+
+# Follow all logs
+docker compose logs -f
+
+# Follow backend logs
+docker compose logs -f server
+
+# Stop containers but preserve named volumes
+docker compose down
```
-## MongoDB Features Demonstrated
+### Kubernetes
-| Feature | Where |
-|---|---|
-| [MongoDB Node.js Driver](https://www.mongodb.com/docs/drivers/node/current/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) | `server/src/database.ts` |
-| [CRUD operations](https://www.mongodb.com/docs/manual/crud/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) | `server/src/employee.routes.ts` |
-| [MongoDB schema validation](https://www.mongodb.com/docs/manual/core/schema-validation/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) | startup validation in `server/src/database.ts` |
-| [Environment-based connection setup](https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel) | `DATABASE_URI` in `server/.env` |
+```bash
+# Inspect application resources
+kubectl get pods -n mean-app
+kubectl get services -n mean-app
+kubectl get pvc -n mean-app
+
+# Inspect monitoring resources
+kubectl get pods -n monitoring
+kubectl get services -n monitoring
+
+# Check backend logs
+kubectl logs -n mean-app deployment/server
+```
+
+These commands assume the resource names and namespaces match the manifests in your checkout.
+
+## Documentation
+
+- [Architecture and Mermaid diagrams](docs/architecture.md)
+- [Deployment Guide](docs/deployment-guide.md)
+- [Troubleshooting Guide](docs/troubleshooting.md)
+
+## Known Limitations and Roadmap
-## Troubleshooting
+These are potential improvements, not claims that the capabilities are already implemented:
-### Cannot connect to MongoDB Atlas
+- [ ] Add and verify actual application and Grafana dashboard screenshots.
+- [ ] Test the complete Docker Compose and Kind deployment from a clean environment.
+- [ ] Confirm MongoDB authentication initialization and connection-string behavior.
+- [ ] Configure and verify a Grafana data source and dashboard.
+- [ ] Consider persistent storage and retention planning for Prometheus.
+- [ ] Plan a tested migration from the old MongoDB image.
+- [ ] Add image vulnerability scanning and document the results.
+- [ ] Consider NetworkPolicies, HTTPS/TLS, and access-control hardening where appropriate.
+- [ ] Add a CD deployment workflow only after deciding on a target environment and safe release process.
-- Verify `DATABASE_URI` in `server/.env`
-- Confirm your database user credentials are correct (Atlas)
-- Confirm your IP is in [Atlas Network Access](https://www.mongodb.com/docs/atlas/security/ip-access-list/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel)
+## Attribution
-### Backend fails to start
+This repository is based on the upstream MEAN Stack Example. Preserve the included `LICENSE` and `NOTICE` files and follow their terms when modifying or redistributing the project.
-- Check Node version: `node --version`
-- Confirm `server/.env` exists
-- Reinstall dependencies in `server`: `npm install`
+---
-### Frontend shows empty data
+## Author
-- Confirm backend is running on `:5300`
-- Open browser dev tools and check network requests
-- Confirm records exist in MongoDB (or run `cd server && npm run seed`)
+
-### Port already in use
+### Shivam Kumar Sinha
-- Change `PORT` in `server/.env`, or stop the process using `:5300`
+**DevOps | Cloud Computing | Linux | Networking | Docker | Kubernetes**
-## Community and Support
+[](https://github.com/Shivam-Infra-Labs)
+[](https://www.linkedin.com/in/shivam-kumar-sinha-0a9248308/)
-- Use [GitHub Issues](https://github.com/mongodb-developer/mean-stack-example/issues) for bugs and feature requests
-- Use [MongoDB Community Forums](https://www.mongodb.com/community/forums/) for general MongoDB questions
+
-## Additional Resources
+---
-- [MEAN Stack Tutorial](https://www.mongodb.com/languages/mean-stack-tutorial?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel)
-- [MongoDB Atlas Docs](https://www.mongodb.com/docs/atlas?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel)
-- [MongoDB Node.js Driver Docs](https://www.mongodb.com/docs/drivers/node/current/?utm_campaign=devrel&utm_source=github&utm_medium=referral&utm_content=mean.stack.example&utm_term=learning.fuel)
+## Support
-## License
+If you find this project helpful, consider giving the repository a ⭐ on GitHub.
-[Apache 2.0](LICENSE)
+
-## Disclaimer
+Made with ❤️ by **Shivam Kumar Sinha**
-This repository is for educational use and is not a supported MongoDB product.
+
diff --git a/architecture/Applicatio-Request-Flow.png b/architecture/Applicatio-Request-Flow.png
new file mode 100644
index 0000000..8e93a82
Binary files /dev/null and b/architecture/Applicatio-Request-Flow.png differ
diff --git a/architecture/Docker-Compose-Architecture.png b/architecture/Docker-Compose-Architecture.png
new file mode 100644
index 0000000..bc4c386
Binary files /dev/null and b/architecture/Docker-Compose-Architecture.png differ
diff --git a/architecture/Kubernete-Architecture.png b/architecture/Kubernete-Architecture.png
new file mode 100644
index 0000000..6de564d
Binary files /dev/null and b/architecture/Kubernete-Architecture.png differ
diff --git a/architecture/MEAN Stack DevOps Infrastructure Banner.png b/architecture/MEAN Stack DevOps Infrastructure Banner.png
new file mode 100644
index 0000000..60adad5
Binary files /dev/null and b/architecture/MEAN Stack DevOps Infrastructure Banner.png differ
diff --git a/architecture/Monitoring-Flow.png b/architecture/Monitoring-Flow.png
new file mode 100644
index 0000000..da9a397
Binary files /dev/null and b/architecture/Monitoring-Flow.png differ
diff --git a/architecture/Overall-System-Architecture.png b/architecture/Overall-System-Architecture.png
new file mode 100644
index 0000000..d1d96b2
Binary files /dev/null and b/architecture/Overall-System-Architecture.png differ
diff --git a/architecture/Security-&-Configuration-Architecture.png b/architecture/Security-&-Configuration-Architecture.png
new file mode 100644
index 0000000..c72a78d
Binary files /dev/null and b/architecture/Security-&-Configuration-Architecture.png differ
diff --git a/client/.dockerignore b/client/.dockerignore
new file mode 100644
index 0000000..5b7f8f3
--- /dev/null
+++ b/client/.dockerignore
@@ -0,0 +1,8 @@
+node_modules
+dist
+.angular
+.git
+.github
+.vscode
+.env
+*.log
diff --git a/client/Dockerfile b/client/Dockerfile
index d00a6cf..ba75c6d 100644
--- a/client/Dockerfile
+++ b/client/Dockerfile
@@ -1,19 +1,34 @@
-FROM node:17-slim AS build
+# ============================================
+# Stage 1: Build Angular application
+# ============================================
+FROM node:22-alpine AS builder
-WORKDIR /usr/src/app
-COPY package.json package-lock.json ./
+WORKDIR /app
-# Install dependencies and copy them to the container
-RUN npm install
+# Install dependencies
+COPY package*.json ./
+RUN npm ci
+
+# Copy application source
COPY . .
-# Build the Angular application for production
-RUN npm run build --prod
+# Production build
+RUN npm run build -- --configuration production
+
+
+# ============================================
+# Stage 2: Serve with NGINX
+# ============================================
+FROM nginx:alpine
-# Configure the nginx web server
-FROM nginx:1.17.1-alpine
+# Copy Angular production build
+COPY --from=builder /app/dist/client/browser/. /usr/share/nginx/html
+
+RUN mv /usr/share/nginx/html/index.csr.html /usr/share/nginx/html/index.html
+
+# Custom NGINX configuration
COPY nginx.conf /etc/nginx/nginx.conf
-COPY --from=build /usr/src/app/dist/client /usr/share/nginx/html
-# Run the web service on container startup.
+EXPOSE 80
+
CMD ["nginx", "-g", "daemon off;"]
diff --git a/client/nginx.conf b/client/nginx.conf
index 9b57ec7..b4519a3 100644
--- a/client/nginx.conf
+++ b/client/nginx.conf
@@ -1,15 +1,32 @@
-events{}
+events {}
http {
-
include /etc/nginx/mime.types;
server {
- listen 8080;
- server_name 0.0.0.0;
+ listen 80;
+ server_name _;
+
root /usr/share/nginx/html;
index index.html;
+ # ============================================
+ # Backend API
+ # ============================================
+ location /api/ {
+ proxy_pass http://server:5300/;
+
+ proxy_http_version 1.1;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+
+ # ============================================
+ # Angular Frontend
+ # ============================================
location / {
try_files $uri $uri/ /index.html;
}
diff --git a/client/src/app/app.spec.ts b/client/src/app/app.spec.ts
new file mode 100644
index 0000000..7d00309
--- /dev/null
+++ b/client/src/app/app.spec.ts
@@ -0,0 +1,34 @@
+import { TestBed } from '@angular/core/testing';
+import { provideRouter } from '@angular/router';
+import { describe, it, expect } from 'vitest';
+
+import { App } from './app';
+
+describe('App', () => {
+ it('should create the application component', async () => {
+ await TestBed.configureTestingModule({
+ imports: [App],
+ providers: [provideRouter([])],
+ }).compileComponents();
+
+ const fixture = TestBed.createComponent(App);
+ fixture.detectChanges();
+
+ expect(fixture.componentInstance).toBeTruthy();
+ });
+
+ it('should display the application title', async () => {
+ await TestBed.configureTestingModule({
+ imports: [App],
+ providers: [provideRouter([])],
+ }).compileComponents();
+
+ const fixture = TestBed.createComponent(App);
+ fixture.detectChanges();
+
+ const toolbar = fixture.nativeElement.querySelector('mat-toolbar');
+
+ expect(toolbar).toBeTruthy();
+ expect(toolbar.textContent).toContain('Employees Management System');
+ });
+});
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..3a1dc3c
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,73 @@
+services:
+
+ # ============================================
+ # MongoDB
+ # ============================================
+ database:
+ image: mongo:4.4
+ container_name: mean-db
+ restart: unless-stopped
+
+ volumes:
+ - mongo-data:/data/db
+
+ healthcheck:
+ test:
+ [
+ "CMD",
+ "mongo",
+ "--eval",
+ "db.adminCommand('ping')"
+ ]
+ interval: 10s
+ timeout: 5s
+ retries: 5
+ start_period: 10s
+
+
+ # ============================================
+ # Node.js + Express Backend
+ # ============================================
+ server:
+ build:
+ context: ./server
+ dockerfile: Dockerfile
+
+ container_name: mean-server
+ restart: unless-stopped
+
+ ports:
+ - "5300:5300"
+
+ environment:
+ DATABASE_URI: mongodb://database:27017/
+ PORT: 5300
+
+ depends_on:
+ database:
+ condition: service_healthy
+
+
+ # ============================================
+ # Angular + NGINX Frontend
+ # ============================================
+ client:
+ build:
+ context: ./client
+ dockerfile: Dockerfile
+
+ container_name: mean-client
+ restart: unless-stopped
+
+ ports:
+ - "8080:80"
+
+ depends_on:
+ - server
+
+
+# ============================================
+# Persistent MongoDB storage
+# ============================================
+volumes:
+ mongo-data:
diff --git a/docs/architecture.md b/docs/architecture.md
new file mode 100644
index 0000000..d49dca0
--- /dev/null
+++ b/docs/architecture.md
@@ -0,0 +1,354 @@
+# MEAN Stack Architecture
+
+## 1. Overview
+
+This document describes the architecture of the Employee Records application and its DevOps deployment environment.
+
+The application uses the MEAN stack:
+
+- **MongoDB:** NoSQL database.
+- **Express.js:** Backend web framework.
+- **Angular:** Frontend framework.
+- **Node.js:** Backend JavaScript runtime.
+
+The project demonstrates how a multi-tier web application can be containerized, run locally with Docker Compose, deployed to Kubernetes using Kind, and monitored with Prometheus and Grafana.
+
+## 2. High-Level Architecture
+
+The application has three primary runtime components:
+
+1. Angular frontend.
+2. Node.js and Express backend.
+3. MongoDB database.
+
+```text
+ User / Browser
+ |
+ v
+ Angular Frontend
+ |
+ HTTP / API
+ |
+ v
+ Node.js / Express
+ |
+ Database Queries
+ |
+ v
+ MongoDB
+```
+
+The frontend handles the user interface, the backend implements application logic and API routes, and MongoDB stores employee records.
+
+## 3. Overall System Architecture
+
+
+
+The system has two main application deployment options:
+
+- Docker Compose for local containerized execution.
+- Kubernetes on Kind for local orchestration.
+
+The monitoring stack is deployed separately in the `monitoring` namespace.
+
+## 4. Application Request Flow
+
+
+
+The normal request-response lifecycle is:
+
+1. A user opens the application in a browser.
+2. Angular renders the user interface.
+3. Angular sends an API request.
+4. NGINX forwards the request to the Express backend.
+5. Express processes the request and interacts with MongoDB.
+6. The backend returns a response.
+7. Angular updates the interface.
+
+### NGINX API Proxy
+
+The frontend NGINX configuration includes:
+
+```nginx
+location /api/ {
+ proxy_pass http://server:5300/;
+}
+```
+
+The trailing slash in `proxy_pass` means the matching `/api/` location prefix is replaced when forwarding the request.
+
+For example:
+
+```text
+Browser request:
+ /api/employees
+
+Backend request:
+ /employees
+```
+
+This is why the backend API routes can use `/employees` while the frontend calls `/api/employees`.
+
+## 5. Docker Architecture
+
+
+
+The project builds separate images for the frontend and backend. MongoDB uses the configured MongoDB image.
+
+### 5.1 Docker Compose Services
+
+| Service | Image/build | Internal port | Host port |
+|---|---|---:|---:|
+| `client` | `./client` Dockerfile | 80 | 8080 |
+| `server` | `./server` Dockerfile | 5300 | 5300 |
+| `database` | `mongo:4.4` | 27017 | Not published |
+
+The backend waits for the database health check before starting through the Compose dependency condition.
+
+### 5.2 Service Communication
+
+Compose services communicate over the internal Docker network using service DNS names.
+
+The backend connects to MongoDB through:
+
+```text
+mongodb://database:27017/
+```
+
+The database hostname is `database`, not `localhost`. Inside a container, `localhost` refers to that same container.
+
+### 5.3 Persistent Storage
+
+The Compose file declares a named volume:
+
+```yaml
+volumes:
+ mongo-data:
+```
+
+The database mounts it at:
+
+```text
+/data/db
+```
+
+This allows MongoDB data to persist when the database container is replaced, as long as the named volume is retained.
+
+### 5.4 Compose Security Scope
+
+The current Compose configuration does not enable MongoDB authentication and does not publish MongoDB's port to the host.
+
+Use this configuration for controlled local development. Do not treat it as a production database security configuration.
+
+## 6. Kubernetes Architecture
+
+
+
+The local Kubernetes environment uses Kind.
+
+### 6.1 Cluster Configuration
+
+The Kind configuration creates a control-plane node and maps:
+
+| Kind node port | Host port | Bind address |
+|---:|---:|---|
+| 30080 | 8081 | 127.0.0.1 |
+
+This makes the frontend available at:
+
+```text
+http://127.0.0.1:8081
+```
+
+### 6.2 Namespace
+
+The application resources are deployed into:
+
+```text
+mean-app
+```
+
+The monitoring resources are deployed into:
+
+```text
+monitoring
+```
+
+Namespaces provide logical separation of resources within the cluster.
+
+### 6.3 Deployments and Services
+
+| Component | Deployment | Service | Service type |
+|---|---|---|---|
+| Frontend | `client` | `client` | NodePort |
+| Backend | `server` | `server` | ClusterIP |
+| MongoDB | `database` | `database` | ClusterIP |
+
+The frontend Service exposes port 80 and maps it to NodePort 30080.
+
+The backend Service exposes port 5300 internally.
+
+The database Service exposes port 27017 internally.
+
+### 6.4 ConfigMap
+
+The project uses `mean-server-config` for non-sensitive backend configuration.
+
+The current ConfigMap provides the backend port:
+
+```yaml
+data:
+ PORT: "5300"
+```
+
+ConfigMaps should not contain passwords, tokens or other sensitive values.
+
+### 6.5 Secret
+
+The Kubernetes manifests reference a Secret named:
+
+```text
+mean-mongo-credentials
+```
+
+The database Deployment expects these keys:
+
+- `MONGO_INITDB_ROOT_USERNAME`
+- `MONGO_INITDB_ROOT_PASSWORD`
+
+The backend Deployment expects:
+
+- `DATABASE_URI`
+
+The database URI must use the same credentials as the MongoDB initialization configuration and include `authSource=admin`.
+
+A Secret resource does not itself create a MongoDB user. The official MongoDB container's initialization behavior creates the root user when initializing a new data directory with the appropriate environment variables. Existing database data and an already initialized PVC require separate consideration.
+
+### 6.6 Persistent Storage
+
+The MongoDB Deployment uses the claim:
+
+```text
+mongo-data-pvc
+```
+
+The claim requests:
+
+- Storage: 1 GiB.
+- Access mode: ReadWriteOnce.
+
+The claim is mounted into MongoDB at `/data/db`.
+
+A PVC provides persistent storage according to the cluster's storage provisioner. It is not a backup system.
+
+### 6.7 Health Probes
+
+The backend Deployment defines:
+
+- Startup probe.
+- Readiness probe.
+- Liveness probe.
+
+All use:
+
+```text
+/healthcheck
+```
+
+The frontend Deployment uses HTTP probes against `/`.
+
+A successful health endpoint response confirms that the endpoint responds; it does not automatically guarantee that every dependency remains healthy after startup.
+
+## 7. Monitoring Architecture
+
+
+
+The monitoring configuration includes Prometheus and Grafana resources.
+
+### 7.1 Prometheus
+
+Prometheus collects metrics from configured targets.
+
+The intended backend target is:
+
+```text
+server.mean-app.svc.cluster.local:5300/metrics
+```
+
+The backend must expose valid Prometheus-format metrics, and Prometheus must be able to reach the target.
+
+### 7.2 Grafana
+
+Grafana visualizes metrics queried from a Prometheus data source.
+
+The actual availability of dashboards and data depends on the Grafana provisioning, data-source configuration and dashboard files included in the monitoring manifests.
+
+### 7.3 Access
+
+The monitoring Services are accessed locally using port forwarding:
+
+```bash
+kubectl port-forward svc/prometheus 9090:9090 -n monitoring
+```
+
+```bash
+kubectl port-forward svc/grafana 3000:3000 -n monitoring
+```
+
+## 8. Security and Configuration Architecture
+
+
+
+The project separates configuration into different resource types:
+
+| Resource | Intended use |
+|---|---|
+| Docker Compose environment | Local container configuration |
+| Kubernetes ConfigMap | Non-sensitive configuration |
+| Kubernetes Secret | Credentials and sensitive values |
+| PVC | Persistent database data |
+| Kubernetes probes | Application health checks |
+
+Security considerations:
+
+- Do not commit credentials to source control.
+- Restrict access to Kubernetes Secrets.
+- Use strong, unique database passwords.
+- Review RBAC permissions.
+- Do not expose the database publicly without a deliberate design.
+- Use maintained container images.
+- Configure TLS for untrusted network paths.
+- Implement and test backups.
+- Review resource limits, network policies and image vulnerabilities.
+
+The diagram is an architectural overview. It does not imply that every recommended security control, notification system or production hardening feature is already deployed.
+
+## 9. Current Project Scope
+
+Implemented configuration represented in this repository includes:
+
+- Dockerfiles for frontend and backend.
+- Docker Compose services and named database volume.
+- Kind cluster configuration.
+- Kubernetes application manifests.
+- ConfigMap and Secret references.
+- MongoDB PersistentVolumeClaim.
+- Frontend and backend health probes.
+- Prometheus and Grafana manifests.
+- GitHub Actions CI workflow.
+
+The following should be treated as future improvements until separately implemented and tested:
+
+- Production-grade TLS and ingress.
+- Automated backups and restore testing.
+- NetworkPolicies and hardened RBAC.
+- Image vulnerability scanning.
+- Autoscaling.
+- GitOps deployment.
+- Cloud deployment.
+
+## 10. Conclusion
+
+This architecture provides a practical learning environment for understanding the path from a full-stack application to containerized services, Kubernetes orchestration, persistent storage and monitoring.
+
+The architecture document should be updated whenever the application code, Docker configuration, Kubernetes manifests or monitoring implementation changes.
\ No newline at end of file
diff --git a/docs/deployment-guide.md b/docs/deployment-guide.md
new file mode 100644
index 0000000..a309410
--- /dev/null
+++ b/docs/deployment-guide.md
@@ -0,0 +1,458 @@
+# MEAN Stack Deployment Guide
+
+This guide explains how to deploy the Employee Records application using Docker Compose and Kubernetes on a local Kind cluster.
+
+It also covers Prometheus and Grafana access.
+
+## 1. Prerequisites
+
+Install and verify the following tools:
+
+- Docker Engine.
+- Docker Compose plugin.
+- kubectl.
+- Kind.
+- Git.
+- Node.js and npm if you also want to run the application directly outside containers.
+
+Check versions:
+
+```bash
+docker --version
+docker compose version
+kubectl version --client
+kind version
+git --version
+```
+
+Run the commands from the repository root:
+
+```bash
+cd ~/Projects/mean-stack-example
+```
+
+## 2. Option A — Deploy with Docker Compose
+
+Docker Compose is the simplest way to start the application locally.
+
+### 2.1 Validate the Compose configuration
+
+```bash
+docker compose config
+```
+
+If this command reports an error, fix the Compose YAML before starting the services.
+
+### 2.2 Build and start the application
+
+```bash
+docker compose up --build -d
+```
+
+### 2.3 Check running containers
+
+```bash
+docker compose ps
+```
+
+View logs:
+
+```bash
+docker compose logs -f
+```
+
+View one service's logs:
+
+```bash
+docker compose logs -f client
+docker compose logs -f server
+docker compose logs -f database
+```
+
+### 2.4 Open the application
+
+```text
+http://localhost:8080
+```
+
+### 2.5 Stop the application
+
+```bash
+docker compose down
+```
+
+The named MongoDB volume is retained by default.
+
+To remove the containers and the named volume as well:
+
+```bash
+docker compose down -v
+```
+
+**Warning:** `docker compose down -v` deletes the Compose-managed database volume and its data. Do not run it if you need to preserve your database.
+
+## 3. Option B — Deploy to Kubernetes using Kind
+
+This section follows the local deployment workflow used for this project.
+
+### 3.1 Build the frontend and backend images
+
+From the repository root:
+
+```bash
+docker build -t mean-stack-example-client:latest ./client
+
+docker build -t mean-stack-example-server:latest ./server
+```
+
+Verify the images:
+
+```bash
+docker images | grep mean-stack-example
+```
+
+### 3.2 Create the Kind cluster
+
+```bash
+kind create cluster --name mean-cluster --config k8s/kind-config.yaml
+```
+
+Check the cluster:
+
+```bash
+kind get clusters
+kubectl cluster-info
+kubectl get nodes
+```
+
+### 3.3 Load the local images into Kind
+
+Kind nodes use their own container runtime. Loading the images makes the locally built images available to the cluster.
+
+```bash
+kind load docker-image mean-stack-example-client:latest --name mean-cluster
+
+kind load docker-image mean-stack-example-server:latest --name mean-cluster
+```
+
+The application Deployments use `imagePullPolicy: IfNotPresent`, so Kubernetes can use the images loaded into the Kind node instead of trying to pull them from a remote registry.
+
+### 3.4 Create the application namespace
+
+```bash
+kubectl apply -f k8s/namespace.yaml
+```
+
+Verify:
+
+```bash
+kubectl get namespace mean-app
+```
+
+### 3.5 Create the MongoDB Secret
+
+The application manifests expect the Secret named `mean-mongo-credentials`.
+
+**Important:** The keys must match the names referenced by `k8s/app/database.yaml` and `k8s/app/server.yaml`.
+
+Use a strong password and replace the placeholder consistently:
+
+```bash
+kubectl create secret generic mean-mongo-credentials \
+ --namespace mean-app \
+ --from-literal=MONGO_INITDB_ROOT_USERNAME=root \
+ --from-literal=MONGO_INITDB_ROOT_PASSWORD='' \
+ --from-literal=DATABASE_URI='mongodb://root:@database:27017/meanStackExample?authSource=admin' \
+ --dry-run=client -o yaml | kubectl apply -f -
+```
+
+Replace both password placeholders with the same actual password. Do not include the angle brackets.
+
+The `DATABASE_URI` must use the same username and password as the MongoDB initialization credentials.
+
+Avoid putting real credentials in source files, screenshots, shell scripts or Git commits. Be aware that commands entered directly in a shell can remain in shell history.
+
+Verify the Secret exists without printing its values:
+
+```bash
+kubectl get secret mean-mongo-credentials -n mean-app
+```
+
+### 3.6 Apply the application manifests
+
+```bash
+kubectl apply -f k8s/app/
+```
+
+Check the resources:
+
+```bash
+kubectl get all -n mean-app
+```
+
+Check the PVC:
+
+```bash
+kubectl get pvc -n mean-app
+```
+
+### 3.7 Check Pod status
+
+```bash
+kubectl get pods -n mean-app -o wide
+```
+
+Wait for the Deployments:
+
+```bash
+kubectl rollout status deployment/client -n mean-app
+kubectl rollout status deployment/server -n mean-app
+kubectl rollout status deployment/database -n mean-app
+```
+
+If a Pod is not ready, inspect its logs and events before proceeding:
+
+```bash
+kubectl describe pods -n mean-app
+kubectl logs deployment/database -n mean-app
+kubectl logs deployment/server -n mean-app
+kubectl logs deployment/client -n mean-app
+```
+
+### 3.8 Open the Kubernetes application
+
+The Kind configuration maps host port `8081` to NodePort `30080`.
+
+Open:
+
+```text
+http://127.0.0.1:8081
+```
+
+If the page does not load, check the Kind cluster, frontend Pod and Service:
+
+```bash
+kind get clusters
+kubectl get pods -n mean-app
+kubectl get svc -n mean-app
+kubectl get endpoints -n mean-app
+```
+
+## 4. Deploy Prometheus and Grafana
+
+The project keeps monitoring resources in a separate namespace.
+
+### 4.1 Create the monitoring namespace
+
+```bash
+kubectl apply -f k8s/monitoring/namespace.yaml
+```
+
+Verify:
+
+```bash
+kubectl get namespace monitoring
+```
+
+### 4.2 Apply the monitoring manifests
+
+```bash
+kubectl apply -f k8s/monitoring/
+```
+
+Check monitoring resources:
+
+```bash
+kubectl get all -n monitoring
+```
+
+Check Pods:
+
+```bash
+kubectl get pods -n monitoring -o wide
+```
+
+If a monitoring Pod is not ready:
+
+```bash
+kubectl describe pods -n monitoring
+kubectl logs deployment/prometheus -n monitoring
+kubectl logs deployment/grafana -n monitoring
+```
+
+The exact Deployment names should match the manifests in the repository.
+
+### 4.3 Access Grafana
+
+Run:
+
+```bash
+kubectl port-forward svc/grafana 3000:3000 -n monitoring
+```
+
+Keep this terminal open.
+
+Open another browser tab:
+
+```text
+http://localhost:3000
+```
+
+The login credentials depend on the Grafana configuration in the repository. Do not assume default credentials if the deployment has been customized. Check the relevant manifest or provisioning configuration.
+
+### 4.4 Access Prometheus
+
+Open a separate terminal and run:
+
+```bash
+kubectl port-forward svc/prometheus 9090:9090 -n monitoring
+```
+
+Keep the terminal open.
+
+Open:
+
+```text
+http://localhost:9090/targets
+```
+
+Inspect the configured scrape targets and their status.
+
+The intended backend target is:
+
+```text
+server.mean-app.svc.cluster.local:5300/metrics
+```
+
+A target is expected to become healthy only if the backend exposes the metrics endpoint and Prometheus can reach it.
+
+## 5. Useful Kubernetes Commands
+
+### Application resources
+
+```bash
+kubectl get all -n mean-app
+kubectl get pods -n mean-app -o wide
+kubectl get svc -n mean-app
+kubectl get pvc -n mean-app
+kubectl get configmap -n mean-app
+kubectl get secrets -n mean-app
+```
+
+### Monitoring resources
+
+```bash
+kubectl get all -n monitoring
+kubectl get pods -n monitoring -o wide
+kubectl get svc -n monitoring
+```
+
+### Logs
+
+```bash
+kubectl logs deployment/client -n mean-app
+kubectl logs deployment/server -n mean-app
+kubectl logs deployment/database -n mean-app
+```
+
+Follow logs:
+
+```bash
+kubectl logs -f deployment/server -n mean-app
+```
+
+### Describe resources
+
+```bash
+kubectl describe deployment server -n mean-app
+kubectl describe pod -n mean-app
+kubectl describe svc client -n mean-app
+```
+
+### Rollout status
+
+```bash
+kubectl rollout status deployment/client -n mean-app
+kubectl rollout status deployment/server -n mean-app
+kubectl rollout status deployment/database -n mean-app
+```
+
+### Restart an application Deployment
+
+```bash
+kubectl rollout restart deployment/server -n mean-app
+```
+
+A restart does not rebuild an image. If you changed source code, rebuild the image, load it into Kind and restart or update the Deployment.
+
+## 6. Rebuild and Update Local Kubernetes Images
+
+When application source code changes:
+
+```bash
+docker build -t mean-stack-example-client:latest ./client
+
+docker build -t mean-stack-example-server:latest ./server
+```
+
+Load the updated images:
+
+```bash
+kind load docker-image mean-stack-example-client:latest --name mean-cluster
+
+kind load docker-image mean-stack-example-server:latest --name mean-cluster
+```
+
+Restart the Deployments:
+
+```bash
+kubectl rollout restart deployment/client -n mean-app
+
+kubectl rollout restart deployment/server -n mean-app
+```
+
+Wait for the rollout:
+
+```bash
+kubectl rollout status deployment/client -n mean-app
+
+kubectl rollout status deployment/server -n mean-app
+```
+
+For a more reproducible workflow, use versioned image tags instead of relying only on `latest`.
+
+## 7. Cleanup
+
+### Delete the application resources
+
+```bash
+kubectl delete -f k8s/app/
+kubectl delete -f k8s/namespace.yaml
+```
+
+Deleting the namespace removes its namespaced resources, including its Secret and PVC object. Depending on the storage provisioner and reclaim policy, the underlying persistent volume may have different deletion behavior. Verify storage resources before cleanup if data matters.
+
+### Delete the monitoring resources
+
+```bash
+kubectl delete -f k8s/monitoring/
+```
+
+### Delete the Kind cluster
+
+```bash
+kind delete cluster --name mean-cluster
+```
+
+Deleting the Kind cluster removes the local cluster and its in-cluster resources. Do not use this as a substitute for a database backup.
+
+## 8. Important Notes
+
+- Run commands from the repository root unless the command says otherwise.
+- The Kubernetes Secret keys must match the keys referenced by the manifests.
+- The MongoDB username and password in `DATABASE_URI` must match the MongoDB initialization credentials.
+- Existing MongoDB data in a PVC may prevent initialization environment variables from creating a new user. Do not delete a PVC to troubleshoot without first considering data loss.
+- The current MongoDB image is `mongo:4.4`; plan a supported-version migration before production use.
+- Prometheus and Grafana access commands require the port-forward process to remain running.
+- A successful `kubectl apply` means resources were accepted by the API server; it does not guarantee that Pods became healthy.
+- Check Pod status, events, logs, Service endpoints and Prometheus targets to validate the deployment.
\ No newline at end of file
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
new file mode 100644
index 0000000..13455c3
--- /dev/null
+++ b/docs/troubleshooting.md
@@ -0,0 +1,610 @@
+# MEAN Stack Troubleshooting Guide
+
+This document covers common issues that may occur while building, running and deploying the MEAN Stack application with Docker Compose, Kind, Kubernetes, Prometheus and Grafana.
+
+## 1. Docker Compose Issues
+
+### 1.1 A container is not starting
+
+Check service status:
+
+```bash
+docker compose ps
+```
+
+Inspect logs:
+
+```bash
+docker compose logs -f
+```
+
+Inspect a specific service:
+
+```bash
+docker compose logs -f client
+docker compose logs -f server
+docker compose logs -f database
+```
+
+Look for image build failures, missing environment variables, database connection errors and port conflicts.
+
+### 1.2 Frontend is not opening on port 8080
+
+Check whether the client container is running:
+
+```bash
+docker compose ps client
+```
+
+Inspect frontend logs:
+
+```bash
+docker compose logs client
+```
+
+Check whether another process is using port 8080:
+
+```bash
+sudo ss -lntp | grep ':8080'
+```
+
+If the port is already in use, stop the conflicting process or change the host port mapping in `docker-compose.yml`.
+
+### 1.3 Backend cannot connect to MongoDB
+
+Check both services:
+
+```bash
+docker compose ps
+docker compose logs database
+docker compose logs server
+```
+
+Inside the Compose network, the backend should connect using the service hostname:
+
+```text
+database:27017
+```
+
+Do not use `localhost:27017` from inside the backend container to reach the database container.
+
+The current Compose configuration uses the `database` service name and does not enable MongoDB authentication by default.
+
+### 1.4 MongoDB data appears to be missing
+
+Check the named volume:
+
+```bash
+docker volume ls
+```
+
+Inspect Compose services and volumes:
+
+```bash
+docker compose config
+docker compose ps
+```
+
+The project uses the named volume `mongo-data`.
+
+Be careful with:
+
+```bash
+docker compose down -v
+```
+
+That command removes the Compose-managed volume and can delete the database data.
+
+## 2. Docker Image Build Issues
+
+### 2.1 Docker build fails
+
+Build each image separately to isolate the failing component:
+
+```bash
+docker build -t mean-stack-example-client:latest ./client
+```
+
+```bash
+docker build -t mean-stack-example-server:latest ./server
+```
+
+Review the first meaningful error in the build output.
+
+Common causes include:
+
+- Incorrect Dockerfile paths.
+- Missing files in the build context.
+- Dependency installation failures.
+- TypeScript or Angular build errors.
+- Incorrect `.dockerignore` rules.
+
+### 2.2 Updated code is not visible in Kubernetes
+
+Building an image on the host does not automatically update an image already loaded into Kind.
+
+Rebuild and reload the image:
+
+```bash
+docker build -t mean-stack-example-server:latest ./server
+
+kind load docker-image mean-stack-example-server:latest --name mean-cluster
+```
+
+Restart the Deployment:
+
+```bash
+kubectl rollout restart deployment/server -n mean-app
+```
+
+Check the rollout:
+
+```bash
+kubectl rollout status deployment/server -n mean-app
+```
+
+Repeat the same process for the frontend if its code changed.
+
+## 3. Kind Cluster Issues
+
+### 3.1 No Kind cluster found
+
+Check:
+
+```bash
+kind get clusters
+```
+
+Create the cluster if it does not exist:
+
+```bash
+kind create cluster --name mean-cluster --config k8s/kind-config.yaml
+```
+
+### 3.2 kubectl has no current context
+
+Check:
+
+```bash
+kubectl config get-contexts
+kubectl config current-context
+```
+
+For this cluster, select:
+
+```bash
+kubectl config use-context kind-mean-cluster
+```
+
+Then verify:
+
+```bash
+kubectl cluster-info
+kubectl get nodes
+```
+
+### 3.3 Images cannot be found by Kubernetes
+
+Check local images:
+
+```bash
+docker images | grep mean-stack-example
+```
+
+Load them into Kind:
+
+```bash
+kind load docker-image mean-stack-example-client:latest --name mean-cluster
+
+kind load docker-image mean-stack-example-server:latest --name mean-cluster
+```
+
+Check the Deployment image and pull policy:
+
+```bash
+kubectl describe deployment client -n mean-app
+kubectl describe deployment server -n mean-app
+```
+
+The project currently uses local image names with `imagePullPolicy: IfNotPresent`.
+
+## 4. Kubernetes Pod Issues
+
+### 4.1 Pod is stuck in Pending
+
+Check:
+
+```bash
+kubectl get pods -n mean-app -o wide
+kubectl describe pod -n mean-app
+kubectl get events -n mean-app --sort-by=.metadata.creationTimestamp
+```
+
+Possible causes:
+
+- PVC is not bound.
+- Insufficient cluster resources.
+- Invalid resource configuration.
+- Scheduling constraints.
+
+Check storage:
+
+```bash
+kubectl get pvc -n mean-app
+kubectl get pv
+```
+
+### 4.2 Pod is in ImagePullBackOff or ErrImagePull
+
+Check the exact image name:
+
+```bash
+kubectl describe deployment client -n mean-app
+kubectl describe deployment server -n mean-app
+```
+
+Check images loaded into Kind and load them again if required.
+
+### 4.3 Pod is in CrashLoopBackOff
+
+Inspect logs:
+
+```bash
+kubectl logs -n mean-app
+```
+
+If the container has restarted, inspect the previous container logs:
+
+```bash
+kubectl logs -n mean-app --previous
+```
+
+Inspect events:
+
+```bash
+kubectl describe pod -n mean-app
+```
+
+Look for missing Secret keys, invalid database URIs, database connection errors and application startup failures.
+
+## 5. MongoDB and Secret Issues
+
+### 5.1 Missing Secret or missing Secret key
+
+Check whether the Secret exists without displaying its values:
+
+```bash
+kubectl get secret mean-mongo-credentials -n mean-app
+```
+
+Inspect the key names only:
+
+```bash
+kubectl get secret mean-mongo-credentials -n mean-app \
+ -o jsonpath='{.data}' | jq 'keys'
+```
+
+The database Deployment expects:
+
+- `MONGO_INITDB_ROOT_USERNAME`
+- `MONGO_INITDB_ROOT_PASSWORD`
+
+The backend Deployment expects:
+
+- `DATABASE_URI`
+
+A Secret created with different key names will not satisfy those references.
+
+### 5.2 Correct the Secret key names
+
+If the Secret is missing or has incorrect keys, recreate/apply it with the correct names:
+
+```bash
+kubectl create secret generic mean-mongo-credentials \
+ --namespace mean-app \
+ --from-literal=MONGO_INITDB_ROOT_USERNAME=root \
+ --from-literal=MONGO_INITDB_ROOT_PASSWORD='' \
+ --from-literal=DATABASE_URI='mongodb://root:@database:27017/meanStackExample?authSource=admin' \
+ --dry-run=client -o yaml | kubectl apply -f -
+```
+
+Replace both password placeholders with the same actual password. Do not include the angle brackets.
+
+Restart the relevant Deployments if they need to reread changed environment variables:
+
+```bash
+kubectl rollout restart deployment/database -n mean-app
+kubectl rollout restart deployment/server -n mean-app
+```
+
+**Important:** Updating a Secret does not automatically change environment variables inside already-running containers. A restart is needed for environment-variable consumers.
+
+### 5.3 MongoDB authentication fails
+
+Check database logs:
+
+```bash
+kubectl logs deployment/database -n mean-app
+```
+
+Check backend logs:
+
+```bash
+kubectl logs deployment/server -n mean-app
+```
+
+Verify that:
+
+- The username is correct.
+- The password is correct.
+- The `DATABASE_URI` uses the same credentials.
+- The URI includes `authSource=admin`.
+- MongoDB initialization completed successfully.
+
+The MongoDB container's initialization variables create the root user when the data directory is initialized for the first time. If a PVC already contains initialized database files, changing initialization variables does not necessarily create or update that user.
+
+Do not delete the PVC as a quick fix. That can destroy persistent database data. First inspect the existing database state and decide how to safely update credentials.
+
+## 6. Frontend and Backend Connectivity
+
+### 6.1 Frontend loads but API requests fail
+
+Check the frontend NGINX configuration:
+
+```bash
+cat client/nginx.conf
+```
+
+The project uses `/api/` as the frontend API path and proxies it to:
+
+```text
+http://server:5300/
+```
+
+Because of the trailing slash in `proxy_pass`, `/api/employees` is forwarded as `/employees`.
+
+Check the backend:
+
+```bash
+kubectl get pods -n mean-app
+kubectl get svc -n mean-app
+kubectl get endpoints -n mean-app
+kubectl logs deployment/server -n mean-app
+```
+
+Make sure the backend Service has endpoints and the frontend can resolve the backend Service name.
+
+### 6.2 Backend health check fails
+
+The backend Kubernetes probes use:
+
+```text
+/healthcheck
+```
+
+Inspect backend logs:
+
+```bash
+kubectl logs deployment/server -n mean-app
+```
+
+Check the Deployment probe configuration:
+
+```bash
+kubectl describe deployment server -n mean-app
+```
+
+The backend starts after its database connection is established in the current application flow. A database connection problem can therefore prevent the health endpoint from becoming available.
+
+## 7. Kubernetes Service and Networking Issues
+
+### 7.1 Application does not open at port 8081
+
+Check:
+
+```bash
+kubectl get svc -n mean-app
+kubectl get pods -n mean-app
+kubectl get endpoints -n mean-app
+```
+
+The frontend Service should expose NodePort `30080`.
+
+Check the Kind configuration:
+
+```bash
+cat k8s/kind-config.yaml
+```
+
+It should map container port `30080` to host port `8081` on `127.0.0.1`.
+
+### 7.2 Service has no endpoints
+
+Check the Service and Pod labels:
+
+```bash
+kubectl describe svc client -n mean-app
+kubectl get pods -n mean-app --show-labels
+```
+
+A Service selector must match the labels on the Pods it should route traffic to.
+
+## 8. Persistent Volume Issues
+
+### 8.1 PVC remains Pending
+
+Check:
+
+```bash
+kubectl get pvc -n mean-app
+kubectl describe pvc mongo-data-pvc -n mean-app
+kubectl get storageclass
+```
+
+A PVC needs a compatible storage provisioner or available persistent volume.
+
+The exact behavior depends on the storage configuration of the Kind cluster.
+
+### 8.2 Database data is not retained
+
+Check that the MongoDB Deployment mounts `mongo-data-pvc` at `/data/db`.
+
+```bash
+kubectl describe deployment database -n mean-app
+kubectl get pvc -n mean-app
+```
+
+A PVC is persistent storage, but data retention also depends on the underlying PV and its reclaim policy.
+
+Keep separate backups of important data.
+
+## 9. Prometheus Troubleshooting
+
+### 9.1 Prometheus target is DOWN
+
+Port-forward Prometheus:
+
+```bash
+kubectl port-forward svc/prometheus 9090:9090 -n monitoring
+```
+
+Open:
+
+```text
+http://localhost:9090/targets
+```
+
+Inspect the target error.
+
+Check monitoring resources:
+
+```bash
+kubectl get pods -n monitoring
+kubectl get svc -n monitoring
+kubectl logs deployment/prometheus -n monitoring
+```
+
+Check the backend:
+
+```bash
+kubectl get pods -n mean-app
+kubectl get svc -n mean-app
+kubectl logs deployment/server -n mean-app
+```
+
+The intended backend target is:
+
+```text
+server.mean-app.svc.cluster.local:5300/metrics
+```
+
+A target can fail if:
+
+- The backend Pod is not ready.
+- The backend Service has no endpoints.
+- The metrics endpoint is not implemented or enabled.
+- The Prometheus scrape configuration has an incorrect target.
+- Prometheus cannot reach the backend Service.
+
+### 9.2 Prometheus is not scraping metrics
+
+Inspect the actual configuration:
+
+```bash
+cat k8s/monitoring/prometheus-config.yaml
+```
+
+Confirm that the scrape job, target hostname, port and metrics path match the backend implementation.
+
+A configured target does not prove that the backend exports valid metrics. Verify the endpoint and inspect the Prometheus target error.
+
+## 10. Grafana Troubleshooting
+
+### 10.1 Grafana page is not opening
+
+Run:
+
+```bash
+kubectl get pods -n monitoring
+kubectl get svc grafana -n monitoring
+kubectl logs deployment/grafana -n monitoring
+```
+
+Start port forwarding:
+
+```bash
+kubectl port-forward svc/grafana 3000:3000 -n monitoring
+```
+
+Open:
+
+```text
+http://localhost:3000
+```
+
+Keep the port-forward terminal running.
+
+### 10.2 Grafana dashboard shows no data
+
+Check:
+
+1. Prometheus is running.
+2. Prometheus targets are healthy.
+3. Grafana has a working Prometheus data source.
+4. The selected dashboard queries match available metric names.
+5. The dashboard time range includes data.
+
+A running Grafana Pod alone does not prove that the data source and dashboards are configured correctly.
+
+## 11. General Diagnostic Commands
+
+Use these commands to collect a quick status overview.
+
+```bash
+kind get clusters
+
+kubectl get nodes
+
+kubectl get pods -n mean-app -o wide
+
+kubectl get svc -n mean-app
+
+kubectl get pvc -n mean-app
+
+kubectl get pods -n monitoring -o wide
+
+kubectl get svc -n monitoring
+
+kubectl get events -A --sort-by=.metadata.creationTimestamp
+```
+
+For a particular Pod:
+
+```bash
+kubectl describe pod -n
+```
+
+For logs:
+
+```bash
+kubectl logs -n
+```
+
+For previous container logs:
+
+```bash
+kubectl logs -n --previous
+```
+
+## 12. Safe Troubleshooting Practices
+
+- Inspect logs and events before deleting resources.
+- Do not delete a PVC without checking whether its data is needed.
+- Do not expose Secret values in screenshots or public issue reports.
+- Avoid committing passwords or database URIs.
+- Rebuild and reload Kind images when application code changes.
+- Check Service endpoints when Pods are running but traffic fails.
+- Confirm Prometheus target health rather than assuming monitoring works because the Pod is running.
+- Keep backups before database upgrades or destructive cleanup.
+
+When reporting an issue, include the command output, relevant Pod events and sanitized logs. Remove passwords, tokens and private connection strings first.
\ No newline at end of file
diff --git a/k8s/app/client.yaml b/k8s/app/client.yaml
new file mode 100644
index 0000000..36db614
--- /dev/null
+++ b/k8s/app/client.yaml
@@ -0,0 +1,58 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: client
+ namespace: mean-app
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: client
+ template:
+ metadata:
+ labels:
+ app: client
+ spec:
+ containers:
+ - name: mean-client
+ image: mean-stack-example-client:latest
+ imagePullPolicy: IfNotPresent
+ ports:
+ - name: http
+ containerPort: 80
+ resources:
+ requests:
+ cpu: 50m
+ memory: 32Mi
+ limits:
+ cpu: 250m
+ memory: 128Mi
+ readinessProbe:
+ httpGet:
+ path: /
+ port: http
+ periodSeconds: 10
+ timeoutSeconds: 2
+ failureThreshold: 3
+ livenessProbe:
+ httpGet:
+ path: /
+ port: http
+ periodSeconds: 20
+ timeoutSeconds: 2
+ failureThreshold: 3
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: client
+ namespace: mean-app
+spec:
+ type: NodePort
+ selector:
+ app: client
+ ports:
+ - name: http
+ port: 80
+ targetPort: 80
+ nodePort: 30080
diff --git a/k8s/app/configmap.yaml b/k8s/app/configmap.yaml
new file mode 100644
index 0000000..7aee2b6
--- /dev/null
+++ b/k8s/app/configmap.yaml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: mean-server-config
+ namespace: mean-app
+data:
+ PORT: "5300"
\ No newline at end of file
diff --git a/k8s/app/database.yaml b/k8s/app/database.yaml
new file mode 100644
index 0000000..22ac62d
--- /dev/null
+++ b/k8s/app/database.yaml
@@ -0,0 +1,78 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: database
+ namespace: mean-app
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: database
+ template:
+ metadata:
+ labels:
+ app: database
+ spec:
+ containers:
+ - name: mongodb
+ image: mongo:4.4
+ imagePullPolicy: IfNotPresent
+ args: ["--auth"]
+ ports:
+ - name: mongodb
+ containerPort: 27017
+
+ env:
+ - name: MONGO_INITDB_ROOT_USERNAME
+ valueFrom:
+ secretKeyRef:
+ name: mean-mongo-credentials
+ key: MONGO_ROOT_USERNAME
+ - name: MONGO_INITDB_ROOT_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: mean-mongo-credentials
+ key: MONGO_ROOT_PASSWORD
+
+ resources:
+ requests:
+ cpu: 100m
+ memory: 256Mi
+ limits:
+ cpu: "500m"
+ memory: 512Mi
+
+ volumeMounts:
+ - name: mongo-storage
+ mountPath: /data/db
+
+ volumes:
+ - name: mongo-storage
+ persistentVolumeClaim:
+ claimName: mongo-data-pvc
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: mongo-data-pvc
+ namespace: mean-app
+spec:
+ accessModes:
+ - ReadWriteOnce
+ resources:
+ requests:
+ storage: 1Gi
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: database
+ namespace: mean-app
+spec:
+ type: ClusterIP
+ selector:
+ app: database
+ ports:
+ - name: mongodb
+ port: 27017
+ targetPort: 27017
diff --git a/k8s/app/server.yaml b/k8s/app/server.yaml
new file mode 100644
index 0000000..da5003d
--- /dev/null
+++ b/k8s/app/server.yaml
@@ -0,0 +1,74 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: server
+ namespace: mean-app
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: server
+ template:
+ metadata:
+ labels:
+ app: server
+ spec:
+ containers:
+ - name: mean-server
+ image: mean-stack-example-server:latest
+ imagePullPolicy: IfNotPresent
+ ports:
+ - name: http
+ containerPort: 5300
+ env:
+ - name: PORT
+ valueFrom:
+ configMapKeyRef:
+ name: mean-server-config
+ key: PORT
+ - name: DATABASE_URI
+ valueFrom:
+ secretKeyRef:
+ name: mean-mongo-credentials
+ key: DATABASE_URI
+ resources:
+ requests:
+ cpu: 100m
+ memory: 128Mi
+ limits:
+ cpu: "500m"
+ memory: 384Mi
+ startupProbe:
+ httpGet:
+ path: /healthcheck
+ port: http
+ periodSeconds: 5
+ failureThreshold: 24
+ readinessProbe:
+ httpGet:
+ path: /healthcheck
+ port: http
+ periodSeconds: 10
+ timeoutSeconds: 2
+ failureThreshold: 3
+ livenessProbe:
+ httpGet:
+ path: /healthcheck
+ port: http
+ periodSeconds: 20
+ timeoutSeconds: 2
+ failureThreshold: 3
+---
+apiVersion: v1
+kind: Service
+metadata:
+ name: server
+ namespace: mean-app
+spec:
+ type: ClusterIP
+ selector:
+ app: server
+ ports:
+ - name: http
+ port: 5300
+ targetPort: 5300
diff --git a/k8s/kind-config.yaml b/k8s/kind-config.yaml
new file mode 100644
index 0000000..51a3c81
--- /dev/null
+++ b/k8s/kind-config.yaml
@@ -0,0 +1,10 @@
+kind: Cluster
+apiVersion: kind.x-k8s.io/v1alpha4
+
+nodes:
+ - role: control-plane
+ extraPortMappings:
+ - containerPort: 30080
+ hostPort: 8081
+ listenAddress: "127.0.0.1"
+ protocol: TCP
diff --git a/k8s/monitoring/dashboard-configmap.yaml b/k8s/monitoring/dashboard-configmap.yaml
new file mode 100644
index 0000000..a445549
--- /dev/null
+++ b/k8s/monitoring/dashboard-configmap.yaml
@@ -0,0 +1,1001 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: nodejs-app-dashboard
+ namespace: monitoring
+ labels:
+ grafana_dashboard: "1"
+data:
+ nodejs-dashboard.json: |
+ {
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": {
+ "uid": "-- Grafana --"
+ },
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "description": "node.js prometheus client basic metrics",
+ "editable": true,
+ "fiscalYearStartMonth": 0,
+ "graphTooltip": 0,
+ "id": null,
+ "links": [],
+ "panels": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "percent"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 10,
+ "x": 0,
+ "y": 0
+ },
+ "id": 6,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "irate(process_cpu_user_seconds_total{instance=~\"$instance\"}[2m]) * 100",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "User CPU - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "irate(process_cpu_system_seconds_total{instance=~\"$instance\"}[2m]) * 100",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Sys CPU - {{instance}}",
+ "refId": "B"
+ }
+ ],
+ "title": "Process CPU Usage",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "s"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 9,
+ "x": 10,
+ "y": 0
+ },
+ "id": 8,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_eventloop_lag_seconds{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "{{instance}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Event Loop Lag",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "none"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 5,
+ "x": 19,
+ "y": 0
+ },
+ "id": 2,
+ "maxDataPoints": 100,
+ "options": {
+ "colorMode": "none",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "percentChangeColorMode": "standard",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "/^__name__$/",
+ "values": false
+ },
+ "showPercentChange": false,
+ "textMode": "name",
+ "wideLayout": true
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "sum(nodejs_version_info{instance=~\"$instance\"}) by (version)",
+ "format": "time_series",
+ "instant": false,
+ "interval": "",
+ "intervalFactor": 1,
+ "legendFormat": "{{version}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Node.js Version",
+ "type": "stat"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "fixedColor": "#F2495C",
+ "mode": "fixed"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "none"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 4,
+ "w": 5,
+ "x": 19,
+ "y": 3
+ },
+ "id": 4,
+ "maxDataPoints": 100,
+ "options": {
+ "colorMode": "none",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "percentChangeColorMode": "standard",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showPercentChange": false,
+ "textMode": "auto",
+ "wideLayout": true
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "sum(changes(process_start_time_seconds{instance=~\"$instance\"}[1m]))",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "{{instance}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Process Restart Times",
+ "type": "stat"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 16,
+ "x": 0,
+ "y": 7
+ },
+ "id": 7,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "right",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "process_resident_memory_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Process Memory - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_heap_size_total_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Total - {{instance}}",
+ "refId": "B"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_heap_size_used_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}}",
+ "refId": "C"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_external_memory_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "External Memory - {{instance}}",
+ "refId": "D"
+ }
+ ],
+ "title": "Process Memory Usage",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "short"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 8,
+ "x": 16,
+ "y": 7
+ },
+ "id": 9,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_active_handles_total{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Active Handler - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_active_requests_total{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Active Request - {{instance}}",
+ "refId": "B"
+ }
+ ],
+ "title": "Active Handlers/Requests Total",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 0,
+ "y": 14
+ },
+ "id": 10,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_heap_space_size_total_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Total - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Total Detail",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 8,
+ "y": 14
+ },
+ "id": 11,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_heap_space_size_used_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Used Detail",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 16,
+ "y": 14
+ },
+ "id": 12,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "expr": "nodejs_heap_space_size_available_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Available Detail",
+ "type": "timeseries"
+ }
+ ],
+ "preload": false,
+ "refresh": "10s",
+ "schemaVersion": 42,
+ "tags": [
+ "nodejs"
+ ],
+ "templating": {
+ "list": [
+ {
+ "current": {
+ "text": [
+ "All"
+ ],
+ "value": [
+ "$__all"
+ ]
+ },
+ "datasource": {
+ "type": "prometheus",
+ "uid": "${DS_PROMETHEUS}"
+ },
+ "definition": "label_values(nodejs_version_info, instance)",
+ "includeAll": true,
+ "label": "instance",
+ "multi": true,
+ "name": "instance",
+ "options": [],
+ "query": "label_values(nodejs_version_info, instance)",
+ "refresh": 1,
+ "regex": "",
+ "sort": 1,
+ "type": "query"
+ }
+ ]
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {},
+ "timezone": "",
+ "title": "NodeJS Application Dashboard",
+ "uid": "nodejs-app-metrics",
+ "version": 1
+ }
\ No newline at end of file
diff --git a/k8s/monitoring/dashboards/nodejs-dashboard.json b/k8s/monitoring/dashboards/nodejs-dashboard.json
new file mode 100644
index 0000000..fd64934
--- /dev/null
+++ b/k8s/monitoring/dashboards/nodejs-dashboard.json
@@ -0,0 +1,992 @@
+{
+ "annotations": {
+ "list": [
+ {
+ "builtIn": 1,
+ "datasource": {
+ "uid": "-- Grafana --"
+ },
+ "enable": true,
+ "hide": true,
+ "iconColor": "rgba(0, 211, 255, 1)",
+ "name": "Annotations & Alerts",
+ "type": "dashboard"
+ }
+ ]
+ },
+ "description": "node.js prometheus client basic metrics",
+ "editable": true,
+ "fiscalYearStartMonth": 0,
+ "graphTooltip": 0,
+ "id": 1,
+ "links": [],
+ "panels": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "percent"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 10,
+ "x": 0,
+ "y": 0
+ },
+ "id": 6,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "irate(process_cpu_user_seconds_total{instance=~\"$instance\"}[2m]) * 100",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "User CPU - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "irate(process_cpu_system_seconds_total{instance=~\"$instance\"}[2m]) * 100",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Sys CPU - {{instance}}",
+ "refId": "B"
+ }
+ ],
+ "title": "Process CPU Usage",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "s"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 9,
+ "x": 10,
+ "y": 0
+ },
+ "id": 8,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_eventloop_lag_seconds{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "{{instance}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Event Loop Lag",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "none"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 3,
+ "w": 5,
+ "x": 19,
+ "y": 0
+ },
+ "id": 2,
+ "maxDataPoints": 100,
+ "options": {
+ "colorMode": "none",
+ "graphMode": "none",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "percentChangeColorMode": "standard",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "/^__name__$/",
+ "values": false
+ },
+ "showPercentChange": false,
+ "textMode": "name",
+ "wideLayout": true
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "sum(nodejs_version_info{instance=~\"$instance\"}) by (version)",
+ "format": "time_series",
+ "instant": false,
+ "interval": "",
+ "intervalFactor": 1,
+ "legendFormat": "{{version}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Node.js Version",
+ "type": "stat"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "fixedColor": "#F2495C",
+ "mode": "fixed"
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "none"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 4,
+ "w": 5,
+ "x": 19,
+ "y": 3
+ },
+ "id": 4,
+ "maxDataPoints": 100,
+ "options": {
+ "colorMode": "none",
+ "graphMode": "area",
+ "justifyMode": "auto",
+ "orientation": "horizontal",
+ "percentChangeColorMode": "standard",
+ "reduceOptions": {
+ "calcs": [
+ "lastNotNull"
+ ],
+ "fields": "",
+ "values": false
+ },
+ "showPercentChange": false,
+ "textMode": "auto",
+ "wideLayout": true
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "sum(changes(process_start_time_seconds{instance=~\"$instance\"}[1m]))",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "{{instance}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Process Restart Times",
+ "type": "stat"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 16,
+ "x": 0,
+ "y": 7
+ },
+ "id": 7,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "right",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "process_resident_memory_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Process Memory - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_heap_size_total_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Total - {{instance}}",
+ "refId": "B"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_heap_size_used_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}}",
+ "refId": "C"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_external_memory_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "External Memory - {{instance}}",
+ "refId": "D"
+ }
+ ],
+ "title": "Process Memory Usage",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "short"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 7,
+ "w": 8,
+ "x": 16,
+ "y": 7
+ },
+ "id": 9,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_active_handles_total{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Active Handler - {{instance}}",
+ "refId": "A"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_active_requests_total{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Active Request - {{instance}}",
+ "refId": "B"
+ }
+ ],
+ "title": "Active Handlers/Requests Total",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 0,
+ "y": 14
+ },
+ "id": 10,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_heap_space_size_total_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Total - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Total Detail",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 8,
+ "y": 14
+ },
+ "id": 11,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_heap_space_size_used_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Used Detail",
+ "type": "timeseries"
+ },
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "fieldConfig": {
+ "defaults": {
+ "color": {
+ "mode": "palette-classic"
+ },
+ "custom": {
+ "axisBorderShow": false,
+ "axisCenteredZero": false,
+ "axisColorMode": "text",
+ "axisLabel": "",
+ "axisPlacement": "auto",
+ "barAlignment": 0,
+ "barWidthFactor": 0.6,
+ "drawStyle": "line",
+ "fillOpacity": 10,
+ "gradientMode": "none",
+ "hideFrom": {
+ "legend": false,
+ "tooltip": false,
+ "viz": false
+ },
+ "insertNulls": false,
+ "lineInterpolation": "linear",
+ "lineWidth": 1,
+ "pointSize": 5,
+ "scaleDistribution": {
+ "type": "linear"
+ },
+ "showPoints": "never",
+ "showValues": false,
+ "spanNulls": false,
+ "stacking": {
+ "group": "A",
+ "mode": "none"
+ },
+ "thresholdsStyle": {
+ "mode": "off"
+ }
+ },
+ "mappings": [],
+ "thresholds": {
+ "mode": "absolute",
+ "steps": [
+ {
+ "color": "green",
+ "value": 0
+ },
+ {
+ "color": "red",
+ "value": 80
+ }
+ ]
+ },
+ "unit": "bytes"
+ },
+ "overrides": []
+ },
+ "gridPos": {
+ "h": 8,
+ "w": 8,
+ "x": 16,
+ "y": 14
+ },
+ "id": 12,
+ "options": {
+ "legend": {
+ "calcs": [
+ "mean",
+ "lastNotNull",
+ "max",
+ "min"
+ ],
+ "displayMode": "table",
+ "placement": "bottom",
+ "showLegend": true
+ },
+ "tooltip": {
+ "hideZeros": false,
+ "mode": "multi",
+ "sort": "none"
+ }
+ },
+ "pluginVersion": "12.2.0",
+ "targets": [
+ {
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "expr": "nodejs_heap_space_size_available_bytes{instance=~\"$instance\"}",
+ "format": "time_series",
+ "intervalFactor": 1,
+ "legendFormat": "Heap Used - {{instance}} - {{space}}",
+ "refId": "A"
+ }
+ ],
+ "title": "Heap Available Detail",
+ "type": "timeseries"
+ }
+ ],
+ "preload": false,
+ "refresh": "",
+ "schemaVersion": 42,
+ "tags": [
+ "nodejs"
+ ],
+ "templating": {
+ "list": [
+ {
+ "current": {
+ "text": [
+ "All"
+ ],
+ "value": [
+ "$__all"
+ ]
+ },
+ "datasource": {
+ "type": "prometheus",
+ "uid": "dg3bo45f3r7y8f"
+ },
+ "definition": "label_values(nodejs_version_info, instance)",
+ "includeAll": true,
+ "label": "instance",
+ "multi": true,
+ "name": "instance",
+ "options": [],
+ "query": "label_values(nodejs_version_info, instance)",
+ "refresh": 1,
+ "regex": "",
+ "sort": 1,
+ "type": "query"
+ }
+ ]
+ },
+ "time": {
+ "from": "now-1h",
+ "to": "now"
+ },
+ "timepicker": {},
+ "timezone": "",
+ "title": "NodeJS Application Dashboard",
+ "uid": "PTSqcpJWk",
+ "version": 1
+}
\ No newline at end of file
diff --git a/k8s/monitoring/grafana/grafana-deployment.yaml b/k8s/monitoring/grafana/grafana-deployment.yaml
new file mode 100644
index 0000000..42bd4e7
--- /dev/null
+++ b/k8s/monitoring/grafana/grafana-deployment.yaml
@@ -0,0 +1,39 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: grafana
+ namespace: monitoring
+spec:
+ replicas: 1
+ strategy:
+ type: Recreate
+ selector:
+ matchLabels:
+ app: grafana
+ template:
+ metadata:
+ labels:
+ app: grafana
+ spec:
+ securityContext:
+ fsGroup: 472
+ containers:
+ - name: grafana
+ image: grafana/grafana:12.2.0
+ ports:
+ - name: http
+ containerPort: 3000
+ resources:
+ requests:
+ cpu: 100m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 256Mi
+ volumeMounts:
+ - name: grafana-storage
+ mountPath: /var/lib/grafana
+ volumes:
+ - name: grafana-storage
+ persistentVolumeClaim:
+ claimName: grafana-data-pvc
diff --git a/k8s/monitoring/grafana/grafana-pvc.yaml b/k8s/monitoring/grafana/grafana-pvc.yaml
new file mode 100644
index 0000000..d9a30ed
--- /dev/null
+++ b/k8s/monitoring/grafana/grafana-pvc.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+ name: grafana-data-pvc
+ namespace: monitoring
+spec:
+ accessModes:
+ - ReadWriteOnce
+ storageClassName: standard
+ resources:
+ requests:
+ storage: 1Gi
diff --git a/k8s/monitoring/grafana/grafana-service.yaml b/k8s/monitoring/grafana/grafana-service.yaml
new file mode 100644
index 0000000..60655f2
--- /dev/null
+++ b/k8s/monitoring/grafana/grafana-service.yaml
@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: grafana
+ namespace: monitoring
+spec:
+ type: ClusterIP
+ selector:
+ app: grafana
+ ports:
+ - name: http
+ port: 3000
+ targetPort: 3000
diff --git a/k8s/monitoring/namespace.yaml b/k8s/monitoring/namespace.yaml
new file mode 100644
index 0000000..d325236
--- /dev/null
+++ b/k8s/monitoring/namespace.yaml
@@ -0,0 +1,4 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: monitoring
diff --git a/k8s/monitoring/prometheus-config.yaml b/k8s/monitoring/prometheus-config.yaml
new file mode 100644
index 0000000..2083295
--- /dev/null
+++ b/k8s/monitoring/prometheus-config.yaml
@@ -0,0 +1,19 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: prometheus-config
+ namespace: monitoring
+data:
+ prometheus.yml: |
+ global:
+ scrape_interval: 30s
+
+ scrape_configs:
+ - job_name: prometheus
+ static_configs:
+ - targets: ["localhost:9090"]
+
+ - job_name: mean-server
+ metrics_path: /metrics
+ static_configs:
+ - targets: ["server.mean-app.svc.cluster.local:5300"]
diff --git a/k8s/monitoring/prometheus-deployment.yaml b/k8s/monitoring/prometheus-deployment.yaml
new file mode 100644
index 0000000..e2c52cf
--- /dev/null
+++ b/k8s/monitoring/prometheus-deployment.yaml
@@ -0,0 +1,39 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: prometheus
+ namespace: monitoring
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: prometheus
+ template:
+ metadata:
+ labels:
+ app: prometheus
+ spec:
+ containers:
+ - name: prometheus
+ image: prom/prometheus:v3.5.0
+ args:
+ - "--config.file=/etc/prometheus/prometheus.yml"
+ - "--storage.tsdb.path=/prometheus"
+ - "--storage.tsdb.retention.time=1d"
+ - "--storage.tsdb.retention.size=100MB"
+ ports:
+ - containerPort: 9090
+ resources:
+ requests:
+ cpu: 100m
+ memory: 128Mi
+ limits:
+ cpu: 300m
+ memory: 256Mi
+ volumeMounts:
+ - name: config
+ mountPath: /etc/prometheus
+ volumes:
+ - name: config
+ configMap:
+ name: prometheus-config
diff --git a/k8s/monitoring/prometheus-service.yaml b/k8s/monitoring/prometheus-service.yaml
new file mode 100644
index 0000000..e6cb96a
--- /dev/null
+++ b/k8s/monitoring/prometheus-service.yaml
@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: prometheus
+ namespace: monitoring
+spec:
+ type: ClusterIP
+ selector:
+ app: prometheus
+ ports:
+ - name: web
+ port: 9090
+ targetPort: 9090
diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml
new file mode 100644
index 0000000..91c152b
--- /dev/null
+++ b/k8s/namespace.yaml
@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: mean-app
+ labels:
+ app.kubernetes.io/part-of: mean-stack-example
+---
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: monitoring
+ labels:
+ app.kubernetes.io/part-of: mean-stack-example
diff --git a/package-lock.json b/package-lock.json
index 0c82933..29f4fdd 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -104,15 +104,14 @@
"license": "MIT"
},
"node_modules/concurrently": {
- "version": "9.2.1",
- "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.2.1.tgz",
- "integrity": "sha512-fsfrO0MxV64Znoy8/l1vVIjjHa29SZyyqPgQBwhiDcaW8wJc2W3XWVOGx4M3oJBnv/zdUZIIp1gDeS98GzP8Ng==",
+ "version": "9.2.5",
+ "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.2.5.tgz",
+ "integrity": "sha512-YMZlvWrTPQEhjKp60XSmMGt60+pffbv6DyRnOMvVO98+J7aF8w8Ui9FhdcOwvSixc/kyR6SoVvmejcn/2lZBqg==",
"dev": true,
- "license": "MIT",
"dependencies": {
"chalk": "4.1.2",
"rxjs": "7.8.2",
- "shell-quote": "1.8.3",
+ "shell-quote": "1.12.0",
"supports-color": "8.1.1",
"tree-kill": "1.2.2",
"yargs": "17.7.2"
@@ -196,11 +195,10 @@
}
},
"node_modules/shell-quote": {
- "version": "1.8.3",
- "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
- "integrity": "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==",
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.12.0.tgz",
+ "integrity": "sha512-PcByqNyT/38F2kDNi006HAMRJaULuBzq/FOsw3qdZvX/GA9W/jamDaRskgHjubHiftXK5sIFxLNkvrXUwcof6Q==",
"dev": true,
- "license": "MIT",
"engines": {
"node": ">= 0.4"
},
diff --git a/screenshots/application-ui.png b/screenshots/application-ui.png
new file mode 100644
index 0000000..fdfafc4
Binary files /dev/null and b/screenshots/application-ui.png differ
diff --git a/screenshots/docker-compose-services.png b/screenshots/docker-compose-services.png
new file mode 100644
index 0000000..4b254cf
Binary files /dev/null and b/screenshots/docker-compose-services.png differ
diff --git a/screenshots/grafana-dashboard.png b/screenshots/grafana-dashboard.png
new file mode 100644
index 0000000..389aaf4
Binary files /dev/null and b/screenshots/grafana-dashboard.png differ
diff --git a/screenshots/kubernetes-resources.png b/screenshots/kubernetes-resources.png
new file mode 100644
index 0000000..563d20a
Binary files /dev/null and b/screenshots/kubernetes-resources.png differ
diff --git a/screenshots/prometheus-targets.png b/screenshots/prometheus-targets.png
new file mode 100644
index 0000000..cdc63ae
Binary files /dev/null and b/screenshots/prometheus-targets.png differ
diff --git a/server/.dockerignore b/server/.dockerignore
new file mode 100644
index 0000000..02085d9
--- /dev/null
+++ b/server/.dockerignore
@@ -0,0 +1,8 @@
+node_modules
+dist
+.git
+.github
+.vscode
+.env
+*.log
+coverage
diff --git a/server/Dockerfile b/server/Dockerfile
index 41ae27a..4e914f9 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -1,11 +1,41 @@
-FROM node:17-slim
-WORKDIR /usr/app
-# Install dependencies and build the project.
-COPY package.json package-lock.json ./
-RUN npm install
+# ============================================
+# Stage 1: Build
+# ============================================
+FROM node:22-alpine AS builder
+
+WORKDIR /app
+
+# Install dependencies
+COPY package*.json ./
+RUN npm ci
+
+# Copy source code
COPY . .
+
+# Build TypeScript application
RUN npm run build
-# Run the web service on container startup.
+
+# ============================================
+# Stage 2: Production runtime
+# ============================================
+FROM node:22-alpine
+
+WORKDIR /app
+
+# Install production dependencies only
+COPY package*.json ./
+RUN npm ci --omit=dev
+
+# Copy compiled application
+COPY --from=builder /app/dist ./dist
+
+# Copy required scripts
+COPY --from=builder /app/scripts ./scripts
+
+EXPOSE 5300
+
+ENV PORT=5300
+
CMD ["node", "dist/server.js"]
diff --git a/server/package-lock.json b/server/package-lock.json
index 4e68314..a1bce5d 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -12,7 +12,8 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.2",
- "mongodb": "^6.3.0"
+ "mongodb": "^6.3.0",
+ "prom-client": "^15.1.3"
},
"devDependencies": {
"@types/cors": "^2.8.17",
@@ -625,6 +626,15 @@
"node": ">= 8"
}
},
+ "node_modules/@opentelemetry/api": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.1.tgz",
+ "integrity": "sha512-gLyJlPHPZYdAk1JENA9LeHejZe1Ti77/pTeFm/nMXmQH/HFZlcS/O2XJB+L8fkbrNSqhdtlvjBVjxwUYanNH5Q==",
+ "license": "Apache-2.0",
+ "engines": {
+ "node": ">=8.0.0"
+ }
+ },
"node_modules/@paralleldrive/cuid2": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/@paralleldrive/cuid2/-/cuid2-2.3.1.tgz",
@@ -1267,6 +1277,12 @@
"bare-path": "^3.0.0"
}
},
+ "node_modules/bintrees": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.2.tgz",
+ "integrity": "sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw==",
+ "license": "MIT"
+ },
"node_modules/body-parser": {
"version": "1.20.5",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz",
@@ -3208,6 +3224,20 @@
"node": ">= 0.8.0"
}
},
+ "node_modules/prom-client": {
+ "version": "15.1.3",
+ "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-15.1.3.tgz",
+ "integrity": "sha512-6ZiOBfCywsD4k1BN9IX0uZhF+tJkV8q8llP64G5Hajs4JOeVLPCwpPVcpXy3BwYiUGgyJzsJJQeOIv7+hDSq8g==",
+ "deprecated": "prom-client has been replaced by @prometheus-io/client",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "@opentelemetry/api": "^1.4.0",
+ "tdigest": "^0.1.1"
+ },
+ "engines": {
+ "node": "^16 || ^18 || >=20"
+ }
+ },
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
@@ -3683,6 +3713,15 @@
"streamx": "^2.15.0"
}
},
+ "node_modules/tdigest": {
+ "version": "0.1.3",
+ "resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.3.tgz",
+ "integrity": "sha512-zbRt+lT+/H4fRItHshczHErVCQnitJk8MfMT24MqFJf3YL7SJJPqGIGeuOdvxXxM/AHFzKBl7WoyaYwqO9s3Kw==",
+ "license": "MIT",
+ "dependencies": {
+ "bintrees": "1.0.2"
+ }
+ },
"node_modules/teex": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/teex/-/teex-1.0.1.tgz",
diff --git a/server/package.json b/server/package.json
index 705c3fb..4fdb7b7 100644
--- a/server/package.json
+++ b/server/package.json
@@ -15,7 +15,8 @@
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.2",
- "mongodb": "^6.3.0"
+ "mongodb": "^6.3.0",
+ "prom-client": "^15.1.3"
},
"devDependencies": {
"@types/cors": "^2.8.17",
diff --git a/server/src/server.ts b/server/src/server.ts
index 79fc6a4..45e7324 100644
--- a/server/src/server.ts
+++ b/server/src/server.ts
@@ -1,10 +1,11 @@
+import client from "prom-client";
import * as dotenv from "dotenv";
import express from "express";
import cors from "cors";
import { connectToDatabase } from "./database";
import { employeeRouter } from "./employee.routes";
-// Load environment variables from the .env file, where the DATABASE_URI is configured
+// Load environment variables
dotenv.config();
const { DATABASE_URI } = process.env;
@@ -20,13 +21,23 @@ if (!DATABASE_URI) {
connectToDatabase(DATABASE_URI)
.then(() => {
const app = express();
+
+ const register = new client.Registry();
+ client.collectDefaultMetrics({ register });
+
app.use(cors());
+
app.get("/healthcheck", (_req, res) => {
res.status(200).json({ status: "ok" });
});
+
+ app.get("/metrics", async (_req, res) => {
+ res.set("Content-Type", register.contentType);
+ res.end(await register.metrics());
+ });
+
app.use("/employees", employeeRouter);
- // start the Express server
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}...`);
});