.. | ||
controllers | ||
data | ||
kubernetes | ||
models | ||
public | ||
routes | ||
util | ||
views | ||
.gitignore | ||
app.js | ||
Dockerfile | ||
package-lock.json | ||
package.json | ||
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
- Features
- Tech Stack
- Project Structure
- Kubernetes Manifests & Scripts
- Prerequisites
- Local Development
- Docker Instructions
- Kubernetes Deployment
- How to Pause / Delete
- 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 server‑side 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 typeNodePort
(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.
- A
-
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:- Namespace
- PV & PVC
- MongoDB StatefulSet
- Book App Deployment
- 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
- Clone the repo
git clone <repo-url> && cd book-app
- Install dependencies
npm install
- Start MongoDB locally (e.g.,
mongod --dbpath ./data
) - Run the app
npm start
- Open your browser at
http://localhost:3000
Docker Instructions
Build and tag the image:
docker build -t book-app:latest .
Run the container:
docker run -d -p 3000:3000 --name book-app book-app:latest
Stop and remove:
docker stop book-app
docker rm book-app
Kubernetes Deployment
- Enter the Kubernetes folder
cd kubernetes
- Prepare the cluster (build image, create namespace)
./prepare-app.sh
- Deploy all resources
./start-app.sh
How to Pause / Delete
To tear down the entire application and free resources:
cd kubernetes
./stop-app.sh
Accessing the App
Once deployed, run:
minikube service book-service -n bookstore-ns
This command opens your default browser to the NodePort–exposed Book App service.
Enjoy managing your book catalog!// filepath: README.md