81 lines
1.8 KiB
Markdown
81 lines
1.8 KiB
Markdown
# Contact List Web Application on Kubernetes
|
|
|
|
## Description
|
|
|
|
A simple web-based contact list app with name and number fields, using Node.js/Express and MongoDB. Data is persisted in MongoDB.
|
|
|
|
## Containers
|
|
|
|
- **contact-app**: Node.js/Express web server serving the frontend and API.
|
|
- **mongo**: Official MongoDB container for data storage.
|
|
|
|
## Kubernetes Objects
|
|
|
|
- **Namespace**: `contact-app` — all resources are grouped here.
|
|
- **Deployment**: Runs the Node.js web app.
|
|
- **StatefulSet**: Runs MongoDB with persistent storage.
|
|
- **PersistentVolume/PersistentVolumeClaim**: Stores MongoDB data.
|
|
- **Service**:
|
|
- `contact-app`: Exposes the web app on a NodePort.
|
|
- `mongo`: Headless service for MongoDB.
|
|
|
|
## Virtual Networks and Volumes
|
|
|
|
- **Headless Service**: For MongoDB pod DNS discovery.
|
|
- **Named Volume**: `/data/mongo` on the host, mounted to MongoDB for persistence.
|
|
|
|
## Container Configuration
|
|
|
|
- The Node.js app uses the `MONGODB_URI` environment variable to connect to MongoDB.
|
|
- MongoDB uses a persistent volume for `/data/db`.
|
|
|
|
## Instructions
|
|
|
|
### Prepare
|
|
|
|
```bash
|
|
chmod +x prepare-app.sh start-app.sh stop-app.sh
|
|
./prepare-app.sh
|
|
```
|
|
|
|
### Run
|
|
|
|
```bash
|
|
./start-app.sh
|
|
```
|
|
|
|
### Access the App
|
|
|
|
1. Get the NodePort:
|
|
```bash
|
|
kubectl -n contact-app get service contact-app
|
|
```
|
|
2. Open in browser:
|
|
`http://<minikube_ip>:<node_port>`
|
|
- Get Minikube IP: `minikube ip`
|
|
|
|
### Pause/Stop
|
|
|
|
```bash
|
|
./stop-app.sh
|
|
```
|
|
|
|
### Delete Volumes (optional)
|
|
|
|
```bash
|
|
rm -rf /data/mongo
|
|
```
|
|
|
|
---
|
|
|
|
## View the Application
|
|
|
|
- Open the NodePort URL in your browser.
|
|
- Add and view contacts via the web UI.
|
|
|
|
---
|
|
|
|
## Notes
|
|
|
|
- Make sure Docker is running and Minikube is started.
|
|
- All kubectl commands assume your context is set to Minikube. |