added README

This commit is contained in:
Sayed Jawad Hussaini 2025-04-23 11:19:37 +02:00
parent 03ea99d24d
commit 5ef8cf7b6e
2 changed files with 399 additions and 0 deletions

399
z2/shop/README.md Normal file
View File

@ -0,0 +1,399 @@
# Book App
A simple online bookstore application where administrators can add or delete books, and registered users can browse the catalog and add books to their shopping cart. The app is containerized with Docker and deployed to Kubernetes using a dedicated namespace, a Deployment for the Node.js app, a StatefulSet for MongoDB (with PersistentVolume and PersistentVolumeClaim), and Services to expose the application.
---
## Table of Contents
1. [Features](#features)
2. [Tech Stack](#tech-stack)
3. [Project Structure](#project-structure)
4. [Kubernetes Manifests & Scripts](#kubernetes-manifests--scripts)
5. [Prerequisites](#prerequisites)
6. [Local Development](#local-development)
7. [Docker Instructions](#docker-instructions)
8. [Kubernetes Deployment](#kubernetes-deployment)
9. [How to Pause / Delete](#how-to-pause--delete)
10. [Accessing the App](#accessing-the-app)
---
## Features
- **Admin**
- Add new books (title, author, price, stock)
- Delete existing books
- **User**
- Browse book catalog
- Add books to a shopping cart
- View cart contents
---
## Tech Stack
- Node.js & Express
- MongoDB (document database)
- EJS templating for serverside views
- Docker & Dockerfile
- Kubernetes (kubectl, Minikube)
---
## Project Structure
```
/
├── app.js # Express app entry point
├── package.json # npm dependencies & scripts
├── Dockerfile # Build instructions for Node.js app
├── controllers/ # Route handlers
│ ├── admin.js
│ └── shop.js
├── models/ # Mongoose schemas
│ ├── book.js
│ └── user.js
├── routes/ # Route definitions
│ ├── admin.js
│ └── shop.js
├── views/ # EJS templates
│ ├── admin/
│ ├── shop/
│ └── includes/
├── public/ # Static assets (CSS, JS)
├── kubernetes/ # K8s manifests & helper scripts
│ ├── namespace.yaml
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── statefulset.yaml
│ ├── prepare-app.sh
│ ├── start-app.sh
│ └── stop-app.sh
└── README.md # This documentation
```
---
## Kubernetes Manifests & Scripts
- `namespace.yaml`
Defines a dedicated Namespace (`bookstore-ns`) for all resources.
- `deployment.yaml`
A Deployment object for the Node.js Book App.
Sets replicas, container image, port, and environment variables.
- `service.yaml`
A Service of type `NodePort` (`book-service`) to expose the Book App on the cluster.
- `statefulset.yaml`
- A `PersistentVolume` for MongoDB data storage.
- A `PersistentVolumeClaim` bound to the PV.
- A `StatefulSet` for MongoDB, ensuring stable network IDs and storage.
- `prepare-app.sh`
Builds the Docker image (`book-app:latest`) and loads it into the Minikube Docker daemon.
Creates the Namespace in the cluster.
- `start-app.sh`
Applies all Kubernetes manifests in the proper order:
1. Namespace
2. PV & PVC
3. MongoDB StatefulSet
4. Book App Deployment
5. Services
- `stop-app.sh`
Deletes all Kubernetes objects to clean up:
- Services
- Deployment & StatefulSet
- PVC & PV
- Namespace
---
## Prerequisites
- Node.js v16+ and npm
- Docker
- Minikube (or any Kubernetes cluster)
- kubectl configured to talk to your cluster
---
## Local Development
1. Clone the repo
```sh
git clone <repo-url> && cd book-app
```
2. Install dependencies
```sh
npm install
```
3. Start MongoDB locally (e.g., `mongod --dbpath ./data`)
4. Run the app
```sh
npm start
```
5. Open your browser at `http://localhost:3000`
---
## Docker Instructions
Build and tag the image:
```sh
docker build -t book-app:latest .
```
Run the container:
```sh
docker run -d -p 3000:3000 --name book-app book-app:latest
```
Stop and remove:
```sh
docker stop book-app
docker rm book-app
```
---
## Kubernetes Deployment
1. Enter the Kubernetes folder
```sh
cd kubernetes
```
2. Prepare the cluster (build image, create namespace)
```sh
./prepare-app.sh
```
3. Deploy all resources
```sh
./start-app.sh
```
---
## How to Pause / Delete
To tear down the entire application and free resources:
```sh
cd kubernetes
./stop-app.sh
```
---
## Accessing the App
Once deployed, run:
```sh
minikube service book-service -n bookstore-ns
```
This command opens your default browser to the NodePortexposed Book App service.
Enjoy managing your book catalog!// filepath: README.md
# Book App
A simple online bookstore application where administrators can add or delete books, and registered users can browse the catalog and add books to their shopping cart. The app is containerized with Docker and deployed to Kubernetes using a dedicated namespace, a Deployment for the Node.js app, a StatefulSet for MongoDB (with PersistentVolume and PersistentVolumeClaim), and Services to expose the application.
---
## Table of Contents
1. [Features](#features)
2. [Tech Stack](#tech-stack)
3. [Project Structure](#project-structure)
4. [Kubernetes Manifests & Scripts](#kubernetes-manifests--scripts)
5. [Prerequisites](#prerequisites)
6. [Local Development](#local-development)
7. [Docker Instructions](#docker-instructions)
8. [Kubernetes Deployment](#kubernetes-deployment)
9. [How to Pause / Delete](#how-to-pause--delete)
10. [Accessing the App](#accessing-the-app)
---
## Features
- **Admin**
- Add new books (title, author, price, stock)
- Delete existing books
- **User**
- Browse book catalog
- Add books to a shopping cart
- View cart contents
---
## Tech Stack
- Node.js & Express
- MongoDB (document database)
- EJS templating for serverside views
- Docker & Dockerfile
- Kubernetes (kubectl, Minikube)
---
## Project Structure
```
/
├── app.js # Express app entry point
├── package.json # npm dependencies & scripts
├── Dockerfile # Build instructions for Node.js app
├── controllers/ # Route handlers
│ ├── admin.js
│ └── shop.js
├── models/ # Mongoose schemas
│ ├── book.js
│ └── user.js
├── routes/ # Route definitions
│ ├── admin.js
│ └── shop.js
├── views/ # EJS templates
│ ├── admin/
│ ├── shop/
│ └── includes/
├── public/ # Static assets (CSS, JS)
├── kubernetes/ # K8s manifests & helper scripts
│ ├── namespace.yaml
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── statefulset.yaml
│ ├── prepare-app.sh
│ ├── start-app.sh
│ └── stop-app.sh
└── README.md # This documentation
```
---
## Kubernetes Manifests & Scripts
- `namespace.yaml`
Defines a dedicated Namespace (`bookstore-ns`) for all resources.
- `deployment.yaml`
A Deployment object for the Node.js Book App.
Sets replicas, container image, port, and environment variables.
- `service.yaml`
A Service of type `NodePort` (`book-service`) to expose the Book App on the cluster.
- `statefulset.yaml`
- A `PersistentVolume` for MongoDB data storage.
- A `PersistentVolumeClaim` bound to the PV.
- A `StatefulSet` for MongoDB, ensuring stable network IDs and storage.
- `prepare-app.sh`
Builds the Docker image (`book-app:latest`) and loads it into the Minikube Docker daemon.
Creates the Namespace in the cluster.
- `start-app.sh`
Applies all Kubernetes manifests in the proper order:
1. Namespace
2. PV & PVC
3. MongoDB StatefulSet
4. Book App Deployment
5. Services
- `stop-app.sh`
Deletes all Kubernetes objects to clean up:
- Services
- Deployment & StatefulSet
- PVC & PV
- Namespace
---
## Prerequisites
- Node.js v16+ and npm
- Docker
- Minikube (or any Kubernetes cluster)
- kubectl configured to talk to your cluster
---
## Local Development
1. Clone the repo
```sh
git clone <repo-url> && cd book-app
```
2. Install dependencies
```sh
npm install
```
3. Start MongoDB locally (e.g., `mongod --dbpath ./data`)
4. Run the app
```sh
npm start
```
5. Open your browser at `http://localhost:3000`
---
## Docker Instructions
Build and tag the image:
```sh
docker build -t book-app:latest .
```
Run the container:
```sh
docker run -d -p 3000:3000 --name book-app book-app:latest
```
Stop and remove:
```sh
docker stop book-app
docker rm book-app
```
---
## Kubernetes Deployment
1. Enter the Kubernetes folder
```sh
cd kubernetes
```
2. Prepare the cluster (build image, create namespace)
```sh
./prepare-app.sh
```
3. Deploy all resources
```sh
./start-app.sh
```
---
## How to Pause / Delete
To tear down the entire application and free resources:
```sh
cd kubernetes
./stop-app.sh
```
---
## Accessing the App
Once deployed, run:
```sh
minikube service book-service -n bookstore-ns
```
This command opens your default browser to the NodePortexposed Book App service.
Enjoy managing your book catalog!

View File